Page 1 of 1

Strip non-numeric characters

Posted: Fri Apr 16, 2004 12:50 pm
by vinnz
I am trying to find a good way to strip all non numeric characters from a string. This is for a phone number that I read from a flat file and this field could be formatted in different ways

Eg:
(xxx)xxx-xxxx
xxx-xxx-xxxx
xxxxxxxxxx
1-xxx-xxx-xxxx

Is it possible only by examining each character in turn or else is there a replace/extract function that I could use with better effect.

I thought I might use the EREPLACE function but I will have to check for every possible character to strip out. I'm hoping there is a way to either strip the non-numeric chars leaving just the digits in the string or go the other way and extract the numeric chars from the string.

thanks in advance,
Paul

Posted: Fri Apr 16, 2004 12:53 pm
by crouse
There's a built-in Transform called DIGITS. Should work for you.

Posted: Fri Apr 16, 2004 12:54 pm
by chulett
You can use Oconv or Iconv with the MCN conversion code to do what you want.

Posted: Fri Apr 16, 2004 3:26 pm
by ray.wurlod
That's exactly what the DIGITS transform does. :)
It's an easier-to-remember name, which is one of the reasons for having Transforms.

Posted: Fri Apr 16, 2004 4:03 pm
by vinnz
Great! Works like a charm.. thanks guys.