Hi,
I am having trouble scanning a text file for illegal characters. The only permitted characters are 0 - 9, + and ,
I had a case where I could not identify a . ( full stop ) by comparing a
character read using midstrt with the predefined allowable characters.
I can find the full stop using the position command but this is all.
the section of code I use is as follows
let>x=0
label>scan
let>x=x+1
readln>%file%,x,line
if>%line%=##EOF##,end
length>%line%,LL
Let>k=0
label>checkloop
let>k=k+1
if>%k%>%LL%,end
midstr>%line%,k,1,check
message>checking character %check% at position %k%
if>%check%=+,checkloop
if>%check%=%comma%,checkloop
if>%check%=0,checkloop
if>%check%=1,checkloop
if>%check%=2,checkloop
if>%check%=3,checkloop
if>%check%=4,checkloop
if>%check%=5,checkloop
if>%check%=6,checkloop
if>%check%=7,checkloop
if>%check%=8,checkloop
if>%check%=9,checkloop
label>alarm
let>flag=flag+1
goto>checkloop
label>end
Message>The scan found %flag% illegal character(s)
This routine does not find a . in the text file
Any ideas
Scanning for illegal characters
Moderators: JRL, Dorian (MJT support)
Hi,
It does find the . - you'll see that if you step through with the debugger. You'll also see that it is equating the . to 0 in line:
if>check=0,checkloop
This is because . is mathematically equal to 0 - it is processing this particular check as a mathematical comparison. The . is the decimal place holder.
The simplest solution in your case is to add the following line to the start of your If> list :
If>check=.,alarm
Another solution is to concatenate something to both the character you're checking and the value you're checking against - that way you can be sure you know what you're comparing and be sure it's a string:
midstr>line,k,1,check
Concat>check,X
...
if>check=0X,checkloop
if>check=1X,checkloop
etc
However, if you're trying to remove certain chars from the line might want to use VBScript's Replace function, or RegExp - both discussed recently in this forum.
It does find the . - you'll see that if you step through with the debugger. You'll also see that it is equating the . to 0 in line:
if>check=0,checkloop
This is because . is mathematically equal to 0 - it is processing this particular check as a mathematical comparison. The . is the decimal place holder.
The simplest solution in your case is to add the following line to the start of your If> list :
If>check=.,alarm
Another solution is to concatenate something to both the character you're checking and the value you're checking against - that way you can be sure you know what you're comparing and be sure it's a string:
midstr>line,k,1,check
Concat>check,X
...
if>check=0X,checkloop
if>check=1X,checkloop
etc
However, if you're trying to remove certain chars from the line might want to use VBScript's Replace function, or RegExp - both discussed recently in this forum.
MJT Net Support
[email protected]
[email protected]
Illegale characters
many Thanks for the guidance. I wasn't aware that it was
mathematically equivalent to zero thought maybe it would do an ascii
compare or something.
Thanks again
Steve
mathematically equivalent to zero thought maybe it would do an ascii
compare or something.
Thanks again
Steve
Still problems
Hi again,
Tried your suggestions and am having problems.
I guess if . is equivalent to 0 then whatever we do with it
it will compare as the same?.
When I looked for IF>check=.,alarm it alarmed with all the 0's in the text
file also.
When I concatted an x to the check and looked for .x, etc it failed all
characters.
Any ideas
Tried your suggestions and am having problems.
I guess if . is equivalent to 0 then whatever we do with it
it will compare as the same?.
When I looked for IF>check=.,alarm it alarmed with all the 0's in the text
file also.
When I concatted an x to the check and looked for .x, etc it failed all
characters.
Any ideas
illegal characters
Hi me Again,
Sorry but I mad a basic error and now have things working fine.
I followed your suggestion to the letter to concat x with check.
Unfortunatelt x is defined as a variable and so I ended up concatting
the variable but checking for X.
All works well now.
many Thanks
Sorry but I mad a basic error and now have things working fine.
I followed your suggestion to the letter to concat x with check.
Unfortunatelt x is defined as a variable and so I ended up concatting
the variable but checking for X.
All works well now.
many Thanks