Function to Replace a string with replacement 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
bandish
Participant
Posts: 41
Joined: Tue Oct 11, 2005 1:30 am

Function to Replace a string with replacement string ?

Post by bandish »

Do we have a function in Parallel jobs to replace every occurrence of a string with replacement string?

Example:

Replace "ABC" with "PQR"

Input String: ABCXYZABC
Output String: PQRXYZPQR
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Not unless you create one.

You could, of course, use a BASIC Transformer stage, which would give you access to the Ereplace() and Change() functions, but these are not natively available in parallel jobs (Modify or parallel Transformer stage).
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

EREPLACE() is not present in PX ??? I cant remember. I know Convert() function is present. Otherwise its not hard to write a C routine to do this.
string.h library in C has a lot of string functions. You can google it up.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Ereplace is not present in parallel jobs, except in the BASIC Transformer stage.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Thanks for the clarification. Could'nt remember.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
bandish
Participant
Posts: 41
Joined: Tue Oct 11, 2005 1:30 am

Post by bandish »

We should have a function similar to Ereplace in Parallel jobs too .. !

So there are two options to implement it:

1. Use Basic transformer in Parallel job.
2. Write a parallel rouitne in C to accomplish the same.

Option 1, Basic transformer will slow down the performance of parallel job, If I am not wrong.
Option 2, Dont have idea on writing parallel routines. Please provide inputs on how to create a parallel routine?

Thanks
Bandish
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

How about if you input is "ABCXYZABCA"
Even if the A that present in the last need to be convert to the corresponding caracter decode value, Convert() as mentioned by DSguru2B will be suitable.
I wish there should be a way to count the total number of presence of the substring using Count() and loop through the count and find the starting position using Index() and replace the given string.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Or as mentioned, google for the C code. http://www.planet-source-code.com/vb/sc ... 0&lngWId=3
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
bandish
Participant
Posts: 41
Joined: Tue Oct 11, 2005 1:30 am

Post by bandish »

My requirement is String Replacement. So convert will not work.

For Ex:

Replace "ABC" with "PQRST"

Input String: ABCXYZABC
Output String: PQRSTXYZPQRST
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

kumar_s wrote:Or as mentioned, google for the C code. http://www.planet-source-code.com/vb/sc ... 0&lngWId=3
That particular code is a horrible example of C code, as the comments following it indicate. Further, it replaces only the first instance.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Check thisrecent post out. See if you bump into any problems.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

I was able to see another very relevent link in google but that was in Ask Tom premium members. :wink:
But its good that we have another Tom (DSguru2B). :wink:
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
Post Reply