Extract Alphanumeric characters and space only
Posted: Thu Jan 11, 2007 5:29 am
I have a requirement to extract only the alphanumeric data from a string. Non alphanumeric data ((!@#$%^&*().etc) should be replaced with empty String. I havent been able to efectively use Oconv() for this. I wrote a routine which seems to work.
One more piece of info : No nulls are expected in input.Leading and trailing spaces should be trimmed in output.Embedded spaces should be spared!
Will this code work? Is there any defect in my approach? Any help is appreciated
Arg1 : input data field
Arg1 Output
"Str^&% ng" --> "Str ng"
" Strin^G" --> "StrinG"
Sorry for the lack of inline comments!
One more piece of info : No nulls are expected in input.Leading and trailing spaces should be trimmed in output.Embedded spaces should be spared!
Will this code work? Is there any defect in my approach? Any help is appreciated
Arg1 : input data field
Arg1 Output
"Str^&% ng" --> "Str ng"
" Strin^G" --> "StrinG"
Code: Select all
L = Len(Trim(Arg1))
A = Trim(Arg1)
B = ""
For i=1 To L Step 1;
Ac = Seq(A[i,1])
Begin Case
Case (Ac > 47 And Ac < 58)
d = A[i,1];
Case (Ac > 64 And Ac < 91)
d = A[i,1];
Case (Ac > 96 And Ac < 123)
d = A[i,1];
Case (Ac = 32)
d = A[i,1];
Case @True
d = "";
End Case
B = B:d;
Next i
Ans = B