Page 1 of 1

Alpha numeric

Posted: Wed Feb 01, 2006 10:48 am
by murali
Hi
I need to extract only alpha numeric from the input string
for example 'as df is xx #$ 90:' is the string and i need to extract
'as df is xx 90' in the out put ,can any one help me in coding this.
Thanks in advance

Posted: Wed Feb 01, 2006 10:55 am
by kcbland
Look at the OCONV function in your DS BASIC manual, the token MCP removes unprintable characters. There's other options to remove not letters and numeric values. You could also use EREPLACE, CHANGE, and CONVERT to name the specific values to be replaced or removed.

Posted: Wed Feb 01, 2006 11:06 am
by murali
Hi kcbland
i have used the oconv function and MCP as token i did not get the result
can u pls code it and show me ,amy be my syantax was wrong
thankyou

Posted: Wed Feb 01, 2006 11:09 am
by chulett
You might want to try using the LETTERS transform that is available under the Built-in/String category. Handles the syntax for you.

Posted: Wed Feb 01, 2006 11:13 am
by sun rays
chulett wrote:You might want to try using the LETTERS transform that is available under the Built-in/String category. Handles the syntax for you.
LETTERS Transform would stip off the numeric characters too.

Posted: Wed Feb 01, 2006 11:14 am
by ArndW
The 'MCA' conversion will return just the alphabetic part, the 'MCN' will do just the numeric but there is no conversion for alphanumeric only. I can do a MATCHES on that pattern, but couldn't get a way to have that answer returned.

You could use the following routine I just clobbered together:

ReturnAlphanumeric(Arg1)

Code: Select all

WorkString = UPCASE(Arg1) ;** makes comparison easier
StringLen  = LEN(WorkString)
Ans        = ''
FOR Index = 1 TO StringLen
   TestChar = WorkString[Index,1]
   IF TestChar < 'A' OR TestChar > 'Z'
   THEN
      IF TestChar = ' ' OR (TestChar => '0' AND TestChar <= '9') THEN Ans := Arg1[Index,1]
   END
   ELSE Ans := Arg1[Index,1]
NEXT I

Posted: Wed Feb 01, 2006 11:20 am
by kcbland
If you put this in a function it would work great also:

Code: Select all

Ans = Arg1
CONVERT "`!@#$%^&*()_+~-=;:,./<>?\|'" TO "" IN Ans
CONVERT '"' TO "" IN Ans
I hope you get the idea. :D

Posted: Wed Feb 01, 2006 11:25 am
by chulett
sun rays wrote:
chulett wrote:You might want to try using the LETTERS transform that is available under the Built-in/String category. Handles the syntax for you.
LETTERS Transform would stip off the numeric characters too.
True. Missed the 'numeric' part of the 'alpha numeric' question... doh! :oops:

Posted: Wed Feb 01, 2006 11:26 am
by ArndW
I though about doing the CONVERT, especially since it is more efficient than a user-written routine; but thought that it might contain more than just the standard non-alphanumeric characters. If the poster knows what characters might be in the data then a CONVERT is better, if it might be any string then the posted code, or possibly a CONVERT in combination with a conversion using 'MCP'.