Replace Special Characters in a String

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
DSFreddie
Participant
Posts: 130
Joined: Wed Nov 25, 2009 2:16 pm

Replace Special Characters in a String

Post by DSFreddie »

Hi All,

I have a char field (length is 8) where I receive values like below,

88@b800
900#@12
123&c99 etc....

I need to replace the special characters & characters in it with Zero,

My output should be as below,

8800800
9000012
1230099

Can you pls let me know how we can accomplish this in Parallel jobs.

Any help would be highly appreciated.

Thanks in advance,
Freddie.
jcthornton
Premium Member
Premium Member
Posts: 79
Joined: Thu Mar 22, 2007 4:58 pm
Location: USA

Post by jcthornton »

I would expect that you would handle that in a Transformer stage. Depending on what is easier, you could check for valid numbers or search for 'special characters'.

I'm not sure what your definition of a special character is for this derivation. From the example, it looks like anything that is not a Decimal digit (0..9) is a special character.

If that is the case, it may be easier to check for your numbers rather than check for special characters.
Jack Thornton
----------------
Spectacular achievement is always preceded by spectacular preparation - Robert H. Schuller
RAJARP
Participant
Posts: 147
Joined: Thu Dec 06, 2007 6:46 am
Location: Chennai

Post by RAJARP »

Hi Freddie,
I couldn't think anything straight for your problem.Bu tI have done something like this in one of my job sometime back.

I am explaining you what i had done

FIELD_A(length 3)-->sample data

1#4
&87
6*@

Requirement-> replace the special characters with zero(same as yours)

I have done it in transformer

i have used three stage variables for extracting the three characters
stage_var1==> FIELD_A[1,1],
stage_var2==> FIELD_A[2,1],
Stage_var3==>FIELD_A[3,1]


then 3 stage varaibels
Stage_var4==> if num(stage_var1)=1 then 'stage_var1' else '0'
Stage_var5==> if num(stage_var2)=1 then 'stage_var2' else '0'
Stage_var6==> if num(stage_var3)=1 then 'stage_var3' else '0'

finally
Stage_var4:Stage_var5:Stage_var6

You can reduce the number of stage variables, by clubbing them like

Code: Select all

 if 
num(FIELD_A[1,1])=1 then FIELD_A[1,1] else '0' 
you can follow the same for your 8 characters

I belive this is kind of crude but there might be someother easier way to achive this.but i don't know whereas DS gurus can enlight us :-)

Regards,
Raja R P
reshma11
Premium Member
Premium Member
Posts: 25
Joined: Mon Oct 13, 2008 7:52 am

Post by reshma11 »

You can use convert function in transformer stage.
Ravi.K
Participant
Posts: 209
Joined: Sat Nov 20, 2010 11:33 pm
Location: Bangalore

Post by Ravi.K »

Use Convert function. Collect All special symbols, characters specify at from list and add same number of zeros at to list.

Convert(%fromlist%,%tolist%,Inputfield)

The below example is based on your data.

Convert('&@#abcdefghijklmnopqrstuvwxyz','00000000000000000000000000000',Inputfield)
Cheers
Ravi K
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

There's no sense of "special" characters here. You want to keep the numeric characters and convert all non-numeric characters to zero.

Code: Select all

svNonNumerics <==  Convert("0123456789","",InLink.TheString)

Convert(svNonNumerics,Str("0",Len(svNonNumerics)),InLink.TheString)
Last edited by ray.wurlod on Wed Dec 29, 2010 3:50 pm, edited 1 time in total.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
manoj_23sakthi
Participant
Posts: 47
Joined: Tue Feb 23, 2010 12:16 am
Location: CHENNAI

Re: Replace Special Characters in a String

Post by manoj_23sakthi »

Hi
In Server some functions are there like mca, ....
In Parallel you have to write routine
write server routine and call to this parallel job it will helps
Thanks,
Manoj
Post Reply