Page 1 of 1

Replace Special Characters in a String

Posted: Wed Oct 20, 2010 8:50 pm
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.

Posted: Wed Oct 20, 2010 11:46 pm
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.

Posted: Thu Oct 21, 2010 12:56 am
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

Posted: Tue Dec 28, 2010 1:30 pm
by reshma11
You can use convert function in transformer stage.

Posted: Wed Dec 29, 2010 12:03 am
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)

Posted: Wed Dec 29, 2010 12:49 am
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)

Re: Replace Special Characters in a String

Posted: Wed Dec 29, 2010 12:56 am
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