Strip non-numeric characters

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
vinnz
Participant
Posts: 92
Joined: Tue Feb 17, 2004 9:23 pm

Strip non-numeric characters

Post 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
crouse
Charter Member
Charter Member
Posts: 204
Joined: Sun Oct 05, 2003 12:59 pm
Contact:

Post by crouse »

There's a built-in Transform called DIGITS. Should work for you.
Craig Rouse
Griffin Resouces, Inc
www.griffinresources.com
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You can use Oconv or Iconv with the MCN conversion code to do what you want.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
vinnz
Participant
Posts: 92
Joined: Tue Feb 17, 2004 9:23 pm

Post by vinnz »

Great! Works like a charm.. thanks guys.
Post Reply