replacing a string
Moderators: chulett, rschirm, roy
replacing a string
Hi,
I have an input string 'fantacy', I would like to covert this string to 'faxyzcy' in the TRANSFORMER Stage. That is 'nta' in the input string should be replaced by 'xyz' in the output. Only the occurrance of 'nta' need to be replaced but not the individual chars...so CONVERT function won't work.
What function I will use to achieve this.
Using 7.5.1 (PX) on UNIX.
I have an input string 'fantacy', I would like to covert this string to 'faxyzcy' in the TRANSFORMER Stage. That is 'nta' in the input string should be replaced by 'xyz' in the output. Only the occurrance of 'nta' need to be replaced but not the individual chars...so CONVERT function won't work.
What function I will use to achieve this.
Using 7.5.1 (PX) on UNIX.
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Give us your thoughts.
In a server job you would have looked at Ereplace() but this is not available in parallel jobs. Clearly an approach that uses substrings and concatenation, plus If..Then..Else, seems to be indicated.
Can you guarantee that the string-to-be-replaced occurs not more than once in the field? If not, you're probably up for a different approach - perhaps an External Filter stage using (perhaps) awk.
In a server job you would have looked at Ereplace() but this is not available in parallel jobs. Clearly an approach that uses substrings and concatenation, plus If..Then..Else, seems to be indicated.
Can you guarantee that the string-to-be-replaced occurs not more than once in the field? If not, you're probably up for a different approach - perhaps an External Filter stage using (perhaps) awk.
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.
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Re: replacing a string
Hi, try the Ereplace function in the transformer:
Example
Ereplace('abcd.doc','.doc','.txt') returns abcd.txt
Hope this helps
Chris
Example
Ereplace('abcd.doc','.doc','.txt') returns abcd.txt
Hope this helps
Chris
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
-
- Premium Member
- Posts: 397
- Joined: Wed Apr 12, 2006 2:28 pm
- Location: Tennesse
StageVar "AntLoc" set to "INDEX(In.Column,'nta',1)"
StageVar "NewString" set to "IF AntLoc=0 THEN In.Column ELSE In.Column[1,AntLoc-1]:'xyz':In.Column[AntLoc+2,9999]"
this will replace the first instance of "ant" with "xyz" in the string in a PX job.
StageVar "NewString" set to "IF AntLoc=0 THEN In.Column ELSE In.Column[1,AntLoc-1]:'xyz':In.Column[AntLoc+2,9999]"
this will replace the first instance of "ant" with "xyz" in the string in a PX job.
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Still awaiting an answer to "Can you guarantee that the string-to-be-replaced occurs not more than once in the field?". Arnd's answer is sufficient if the answer is "yes", but not if the answer is "no".
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.
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact: