Is there a way to remove characters from String except 0-9

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
tombastian
Premium Member
Premium Member
Posts: 41
Joined: Fri Jun 04, 2004 5:52 am
Location: Bangalore

Is there a way to remove characters from String except 0-9

Post by tombastian »

Hi All,
In DataStage, is there any way to remove all the characters from a String except digits 0 to 9.

Thanks In Advance,
Tom.
morneh
Participant
Posts: 17
Joined: Wed Jan 28, 2004 8:09 am
Contact:

Post by morneh »

Only way I've been able to do it was to write a routine that check each character and if it's not A - Z or 0 - 9 then it would skip it and continue to the next.

If it is one of the wanted characters, it would concat it to a new string and at the end of the routine pass back this "cleaned up" string to you.

Obviously running this through a lot of data does impact your performance quite heavily.
naren6876
Participant
Posts: 233
Joined: Mon Feb 07, 2005 7:19 pm

Re: Is there a way to remove characters from String except 0

Post by naren6876 »

Use Result = Oconv("InputString","MCN")
tombastian wrote:Hi All,
In DataStage, is there any way to remove all the characters from a String except digits 0 to 9.

Thanks In Advance,
Tom.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Naren's post is correct, just remember to remove the quotes around the first parameter 8)
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Or something a little less obtuse:

Code: Select all

DIGITS(YourField)
Does the exact same Oconv under the covers but at least you have an idea what is going on. Check out the other Transforms that come with the product, there's some handy stuff in there. :wink:

:idea: Next time you need to do something like this and aren't sure if there is something built in or not, I've found something I think is pretty handy. Bring up the Online Help in the Designer and switch to the Index tab. Type BASIC and then arrow down to 'alphabetic list of' and hit enter. This is a nice page in-and-of itself, but wait - there's more!

You'll see a note at the top of the page saying something on the order of 'if you are unsure of what you need, see BASIC Tasks. You can also get there right from the Index. Lots of good functions listed by task type. Wouldn't have (directly) solved your digits problem, but a good resource.

You should also check out all of the various Conversion Codes available for the Iconv/Oconv functions. It's amazing how many things other than dates that you can 'conv' with them. :lol:
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply