How can I search a string for XYZ and replace with spaces
Moderators: chulett, rschirm, roy
How can I search a string for XYZ and replace with spaces
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
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
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:
Hope this helps!
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
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!"
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!"
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.
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!"
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!"
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!"
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!"
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!"
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!"
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.