Replacing a string with another string
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 27
- Joined: Mon Jul 09, 2012 6:51 am
- Location: Chennai
Replacing a string with another string
I have strings
MumbaiBangaloreChennai,
NaviMumbaiBangaloreChennai,
MumbaiPuneBangaloreKolkataChennai,
PuneBangaloreKolkataChennai,
I need to replace Kolkata with Calcutta if it exists in the string. How it can be achieved? This is in Datastage 8.1
MumbaiBangaloreChennai,
NaviMumbaiBangaloreChennai,
MumbaiPuneBangaloreKolkataChennai,
PuneBangaloreKolkataChennai,
I need to replace Kolkata with Calcutta if it exists in the string. How it can be achieved? This is in Datastage 8.1
Regards,
Aravind V A
Aravind V A
-
- Premium Member
- Posts: 536
- Joined: Thu Oct 11, 2007 1:48 am
- Location: Bangalore
Re: Replacing a string with another string
Hi,
I think using Index function,u can achieve your requirment.Try serching in this forum,you will get multiple threads.
Thanks
Prasoon
I think using Index function,u can achieve your requirment.Try serching in this forum,you will get multiple threads.
Thanks
Prasoon
-
- Participant
- Posts: 27
- Joined: Mon Jul 09, 2012 6:51 am
- Location: Chennai
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Hi aravindunni31,
The below logic may be help full-
Please correct me if I am wrong.
The below logic may be help full-
Code: Select all
If Index(InputCol,"Kolkata",1) =0 Then InputCol Else InputCol [1,Index(InputCol,"Kolkata",1)-1] :"Calcutta":InputCol [Index(InputCol,"Kolkata",1) +7, Index(InputCol, Right(InputCol,1),1)]
-
- Participant
- Posts: 27
- Joined: Mon Jul 09, 2012 6:51 am
- Location: Chennai
-
- Participant
- Posts: 27
- Joined: Mon Jul 09, 2012 6:51 am
- Location: Chennai
I am doing this in a parallel job using a transformer. EReplace function is not there. Can you please tell me what are the functions used to achieve thisray.wurlod wrote:Use the pxEreplace() function (which you can find on DSXchange) or upgrade to version 9.1 and use Ereplace() or Change() function. ...
Regards,
Aravind V A
Aravind V A
-
- Premium Member
- Posts: 1044
- Joined: Wed Sep 29, 2004 3:30 am
- Location: Nottingham, UK
- Contact:
Sadly I must advise that you DO NOT use the pxEreplace function. This is from IBM support:
So, how do BuildOps work? I've never done one.
Getting back to the OP's problem - for simple cases, where you are sure that you have only one occurrence of the search string, then the index function can be used to find the string and you can slice it yourself in a derivation. Something like this, adjust slightly if your string might be longer than 999 characters:
The index(input,"Kolkata") call should probably be moved out into a stage variable for efficiency.
This confirms my suspicion that the char* return type is almost entirely useless. The only safe thing that you can return with a char* routine is a fixed constant string such as an error message. It baffles me why IBM do not allow std::string as a return type, as this is precisely the reason that std::string was invented.IBM wrote:Good Morning,
I did some further research and found some more information:
It would seem that there is no way to free the memory that is allocated in a C transform routine. You should not use malloc in a transform routine.
We suggest that if you have a complex function then you may want to consider using a BuildOp instead. Calling C Transform routines is really meant for routines that return native C data types (primitive data types). Complex functions should be created as BuildOp's or Custom C stages.
I hope this advice helps
Many thanks
Mark H
So, how do BuildOps work? I've never done one.
Getting back to the OP's problem - for simple cases, where you are sure that you have only one occurrence of the search string, then the index function can be used to find the string and you can slice it yourself in a derivation. Something like this, adjust slightly if your string might be longer than 999 characters:
Code: Select all
=If index(input,"Kolkata") = 0 Then input Else input[1,index(input,"Kolkata")-1] : "Calcutta" : input[index(input,"Kolkata")+7,999])
Phil Hibbs | Capgemini
Technical Consultant
Technical Consultant
Re: Replacing a string with another string
try this
Convert('KolkataMumai','Calcutta','Kolkata') it works in parallel transformer too..
Convert('KolkataMumai','Calcutta','Kolkata') it works in parallel transformer too..
-
- Participant
- Posts: 27
- Joined: Mon Jul 09, 2012 6:51 am
- Location: Chennai
Re: Replacing a string with another string
Convert Wont work for this scenario. Convert will convert only for one character. Not string
Regards,
Aravind V A
Aravind V A
-
- Premium Member
- Posts: 1044
- Joined: Wed Sep 29, 2004 3:30 am
- Location: Nottingham, UK
- Contact:
Re: Replacing a string with another string
That will convert the third parameter replacing 'K' -> 'C', 'o's -> 'a', 'k' -> 'c', 'a' -> 'u', etc., and removing all 'M', 'u', 'm' and 'i' characters. Not exactly what the OP wanted.saidvs wrote:try this
Convert('KolkataMumai','Calcutta','Kolkata') it works in parallel transformer too..
Phil Hibbs | Capgemini
Technical Consultant
Technical Consultant
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
If you're not going to use pxEreplace() then you need a combination of Index() function and substring operators. For example:
Code: Select all
sv1 <-- Index(InLink.TheString, "Kolkata", 1)
sv2 <-- If sv1 Then InLink.TheString[1,sv1-1] : "Calcutta" : InLink.TheString[sv1+7,Len(InLink.TheString)-7]
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.