How can I search a string for XYZ and replace with spaces

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

Marley777
Premium Member
Premium Member
Posts: 316
Joined: Tue Jan 27, 2004 3:26 pm

How can I search a string for XYZ and replace with spaces

Post by Marley777 »

Thanks for reading!

In a transformer stage I want to search a string for XYZ and replace with spaces. How can I do this without building a routine?


Thanks
Maveric
Participant
Posts: 388
Joined: Tue Mar 13, 2007 1:28 am

Post by Maveric »

Try convert function.
Maveric
Participant
Posts: 388
Joined: Tue Mar 13, 2007 1:28 am

Post by Maveric »

Try convert function.
Maveric
Participant
Posts: 388
Joined: Tue Mar 13, 2007 1:28 am

Post by Maveric »

Try convert function.
Marley777
Premium Member
Premium Member
Posts: 316
Joined: Tue Jan 27, 2004 3:26 pm

Post by Marley777 »

Convert appears to be a single character conversion instead of a substring conversion.
jdmiceli
Premium Member
Premium Member
Posts: 309
Joined: Wed Feb 22, 2006 10:03 am
Location: Urbandale, IA

Post by jdmiceli »

Just for clarification, are you wanting to replace an entire string 'XYZ' or any incidents of ('X','Y','Z')?

Convert is probably what you want, but make sure you remember how it works. This is from the docs:

Code: Select all

Syntax
Convert (list, new.list, string)
list is a list of characters to replace. If list is a null value it generates a
run-time error.
new.list is a corresponding list of substitute characters. If new.list is a
null value, it generates a run-time error.
string is an expression that evaluates to the string, or a variable
containing the string. If string is a null value, null is returned.
Remarks
The two lists of characters correspond. The first character of new.list
replaces all instances of the first character of list, the second replaces
the second, and so on. If the two lists do not contain the same number
of characters:
�� Any characters in list with no corresponding characters in new.list
are deleted from the result.
�� Any surplus characters in new.list are ignored.
Example
This is an example of Convert used as a function:
MyString ="NOW IS THE TIME"
ConvStr = Convert("TI", "XY", MyString)
* all T => X, I => Y
* At this point ConvStr is: NOW YS XHE XYME
ConvStr = Convert("XY", "Z", ConvStr)
* all X => Z, Y => ""
* At this point ConvStr is: NOW S ZHE ZME
Hope this helps!
Bestest!

John Miceli
System Specialist, MCP, MCDBA
Berkley Technology Services


"Good Morning. This is God. I will be handling all your problems today. I will not need your help. So have a great day!"
Marley777
Premium Member
Premium Member
Posts: 316
Joined: Tue Jan 27, 2004 3:26 pm

Post by Marley777 »

Hi, we need to replace the enite string xyz. .

Example -

We currently have

attn richard
or
c/o richard

We want to remove attn and c/o and replace with spaces.

richard
richard
jdmiceli
Premium Member
Premium Member
Posts: 309
Joined: Wed Feb 22, 2006 10:03 am
Location: Urbandale, IA

Post by jdmiceli »

Came up with another option that should do what you want:

use eReplace() instead. It would look something like this:
eReplace(<fieldname,linkname,etc>, "<String to replace>", "<replacement values>", [# of instances to replace], [occurance to start from]) - the last two are optional.

So using what you gave as an example, it might look like this in the transformer's derivation field for that field:
eReplace(link.field, "attn: Richard", " ")

I would think though that you would not want a space for each letter replaced as that would pad the text of the field, moving it to the right. Just a thought.
Bestest!

John Miceli
System Specialist, MCP, MCDBA
Berkley Technology Services


"Good Morning. This is God. I will be handling all your problems today. I will not need your help. So have a great day!"
Marley777
Premium Member
Premium Member
Posts: 316
Joined: Tue Jan 27, 2004 3:26 pm

Post by Marley777 »

Hi thanks or the info.

We don't know what in the field. It's a free form filed. All we know is we need to get rid of any occurence of attn or c/o.


In java we would use something like

StringUtil.replace("&",xml,"&"); - in field called xml, replace all & with &amp.

how do we do this in DataStage.
Marley777
Premium Member
Premium Member
Posts: 316
Joined: Tue Jan 27, 2004 3:26 pm

Post by Marley777 »

Hi thanks or the info.

We don't know what in the field. It's a free form filed. All we know is we need to get rid of any occurence of attn or c/o.


In java we would use something like

StringUtil.replace("&",xml,"&"); - in field called xml, replace all & with &amp.

how do we do this in DataStage.
jdmiceli
Premium Member
Premium Member
Posts: 309
Joined: Wed Feb 22, 2006 10:03 am
Location: Urbandale, IA

Post by jdmiceli »

Try the eReplace(InLink.field, "attn: "," ") and see what happens. That goes in the derivation field in the transform stage for the field you are looking at. You may even have to make it a stage variable, but I doubt it.
Bestest!

John Miceli
System Specialist, MCP, MCDBA
Berkley Technology Services


"Good Morning. This is God. I will be handling all your problems today. I will not need your help. So have a great day!"
Marley777
Premium Member
Premium Member
Posts: 316
Joined: Tue Jan 27, 2004 3:26 pm

Post by Marley777 »

We can't use a BASIC Transformer here at our company. We are using a Transformer stage not a Basic Transformer stage. Ascential told us not to use Basic Transformer. We also have had many issues with the Basic Transformer. How can we do this in a Transformer not Basic Transformer.
Marley777
Premium Member
Premium Member
Posts: 316
Joined: Tue Jan 27, 2004 3:26 pm

Post by Marley777 »

How can we do this in a Transformer not Basic Transformer?
jdmiceli
Premium Member
Premium Member
Posts: 309
Joined: Wed Feb 22, 2006 10:03 am
Location: Urbandale, IA

Post by jdmiceli »

I just noticed you are using parallel, not server edition. I am afraid I have no idea how to do it in parallel. I searched for some things in the Parallel forum and the only option I see for you is the Convert function. Sorry, I tried... :?
Bestest!

John Miceli
System Specialist, MCP, MCDBA
Berkley Technology Services


"Good Morning. This is God. I will be handling all your problems today. I will not need your help. So have a great day!"
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The C++ code for a parallel Ereplace() function has already been posted in this forum. Search for it.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply