Read Line and return only alphanumerical characters
Moderators: JRL, Dorian (MJT support)
Read Line and return only alphanumerical characters
I need help writing a scrypt that will take a text file, read the first line and it there are any punctuation or spaces that it will delete them and only return the numbers or letters. For example, if the line has 723.15, I only want to get 72315...... Thanks for you help
Something like this:
ReadLn>filename,1,line
Let>comma=,
Let>period=.
Let>colon=:
Let>semicolon=;
StringReplace>line,comma,,line
StringReplace>line,period,,line
StringReplace>line,colon,,line
StringReplace>line,semicolon,,line
... You get the idea ...
ReadLn>filename,1,line
Let>comma=,
Let>period=.
Let>colon=:
Let>semicolon=;
StringReplace>line,comma,,line
StringReplace>line,period,,line
StringReplace>line,colon,,line
StringReplace>line,semicolon,,line
... You get the idea ...
MJT Net Support
[email protected]
[email protected]
You can also do this the "old fashioned" way to have total control and not have to predict which characters you might encounter. In the code from support, any characters not handled explicitly would not be removed from the string.
Try this if you want only numeric. change ValidChar to include any other characters you want to include in your final string.
rem> ValidChar holds all characters you want to include in your string
let>ValidChar=0123456789
rem> RawString is anything you might read with ReadLn
let>RawString=0943)(J)(U54E)(JE)(JJ100J$$%^%*7!.,
rem> you need the length of the string to know when you are at the end
length>%RawString%,LenRawString
rem> set the place holder for the current digit being tested
let>Digit=0
rem> clear out the final string by setting it equal to
let>FinalString=
label>NextDigit
rem> increment the digit being tested on each loop
let>Digit=Digit+1
rem> isolate the specific digit with the MidStr command
Midstr>%RawString%,%Digit%,1,DigitResult
Rem> check to see if it is in the valid list
Pos>%DigitResult%,%ValidChar%,1,CharFound
if>%CharFound%>0
rem> if it is in the list, then concatenate it to the string of valid chars
Concat>FinalString,DigitResult
endif>
rem> as long as you are not at the end of the string, go get the next char
if>%Digit%NextDigit
endif>
mdl>%RawString% %CRLF% %FinalString%
There are dozens of ways to do just about every task in programming, this is just another option. It has it's advantages.
SkunkWorks
Try this if you want only numeric. change ValidChar to include any other characters you want to include in your final string.
rem> ValidChar holds all characters you want to include in your string
let>ValidChar=0123456789
rem> RawString is anything you might read with ReadLn
let>RawString=0943)(J)(U54E)(JE)(JJ100J$$%^%*7!.,
rem> you need the length of the string to know when you are at the end
length>%RawString%,LenRawString
rem> set the place holder for the current digit being tested
let>Digit=0
rem> clear out the final string by setting it equal to
let>FinalString=
label>NextDigit
rem> increment the digit being tested on each loop
let>Digit=Digit+1
rem> isolate the specific digit with the MidStr command
Midstr>%RawString%,%Digit%,1,DigitResult
Rem> check to see if it is in the valid list
Pos>%DigitResult%,%ValidChar%,1,CharFound
if>%CharFound%>0
rem> if it is in the list, then concatenate it to the string of valid chars
Concat>FinalString,DigitResult
endif>
rem> as long as you are not at the end of the string, go get the next char
if>%Digit%NextDigit
endif>
mdl>%RawString% %CRLF% %FinalString%
There are dozens of ways to do just about every task in programming, this is just another option. It has it's advantages.
SkunkWorks