Page 1 of 1

Replacing a substr with a single value

Posted: Fri Jan 13, 2006 7:04 am
by varshanswamy
Hi,

I need to do the following in datastage
input string
lmundada%3Dabc%3Dlmno%2D

I need to replace all '%3D' with ':' and all %2D with ','

output string
lmundada:abc:lmno,

I used convert function but convert function converts all occurances of % to :.

I need to do something similar to replace function in oracle.

Since I am using datastage px, I cannot use the ereplace or the change function, which need the basic transformer to be used.

regards,
varsha

Re: Replacing a substr with a single value

Posted: Fri Jan 13, 2006 9:54 am
by kwwilliams
Try Convert('%3D',':',Input.String). that should work to replace your first string. Use stage variables and convert once for the %3D value and again for the next value. You might try nesting the function, but I like using stage variables instead makes it easier to read later. Let me know if this works for you,

Re: Replacing a substr with a single value

Posted: Fri Jan 13, 2006 11:24 am
by varshanswamy
kwwilliams wrote:Try Convert('%3D',':',Input.String). that should work to replace your first string. Use stage variables and convert once for the %3D value and again for the next value. You might try nesting the function, but I like using stage variables instead makes it easier to read later. Let me know if this works for you,
The problem is the Convert function is replacing even %2D along with the %3D, as it encounters % and is replacing it with :

Posted: Fri Jan 13, 2006 2:51 pm
by ray.wurlod
Is this a literal string "%3D" or are you referring to a single character 0x3d ?

Convert() is a character-by-character conversion; Convert('%3D',':',Arg) is the same as Convert('%',':',Arg) then Convert('3','',Arg) then Convert('D','',Arg) - which is not the effect you intended.

In server jobs and BASIC Transformer stages you could use the Ereplace function, which does perform substring replacement. However I don't believe there's an equivalent in parallel jobs unless you create your own (for example as a buildop or as a parallel routine).

If the substring only occurs once, you could wrap the Convert() function in an If..Then..Else construct. Test for the existence of '%3D' and only apply the Convert() if it's found.