Page 1 of 1

What function to use for replacing string?

Posted: Wed Feb 09, 2011 5:30 am
by blazDelParis
on a UNIX machine, with PX server (v8.01)

For example, in a field i get filePaths.
but the slashes are twins ex : "C:\\toto\\toto1\\toto2\\toto3"

in a transformerStage (on a parallel job); how can I simply replace the double slash into a simple slash like : "C:\toto\toto1\toto2\toto3"

in a transformer stage (on parallel job) , Ereplace(), change() and pxEreplace() don't work as the compiler do not recognize these functions.
For internal reasons, I can't use an external routine.
left() and right() use is not a simple solution as the number of double-slash may change.
Convert() can't work either as it replaces only one character with another only one character.

Of course there is very badly ugly solution.
In a transformer stage, I set 25 stages variables using Field() function with "\" as separator and 1 to 25 as number of occurences.
Then I can concatenate the 25 stage variables if there are not empty.

But if there is more than 13 doubles slashes (and it can happen), I'll miss a part of the filePath.

Have you got an idea ?

Posted: Wed Feb 09, 2011 8:25 am
by chulett
Split from this topic. I had to guess on the particulars (version, O/S) so if either are wrong please edit your post and correct them.

Posted: Wed Feb 09, 2011 11:19 am
by ray.wurlod
Search DSXchange for source code for pxEreplace() - it does not ship with DataStage so you have to create a parallel routine of it.

Posted: Thu Feb 10, 2011 5:13 am
by blazDelParis
thank you for your answer.
my boss doesn't like me using routines for some security reasons he says.
So I would rather like not using it but if it is the only way...
it's a pity there is not such a basic function shipped with datastage.

So i guess, I'll get the same problem for regular expressions.

If someone doesn't want to search here is the links to the good routines :

pxEreplace() :
http://66.34.129.47/viewtopic.php?t=138 ... 1b9c56fd6f

matching a regular expression :
http://66.34.129.47/viewtopic.php?t=107 ... 1b9c56fd6f

thanks to the authors of these routines

Posted: Thu Feb 10, 2011 3:15 pm
by ray.wurlod
There IS a BASIC function (Ereplace()). But you can only use BASIC functions in the BASIC Transformer stage in parallel jobs.