Find the character in a string
Moderators: chulett, rschirm, roy
Find the character in a string
Hello to all,
can anyone help me on this issue:
I have this string: RM1246873TS98475
and I want that concatenate WS to the next alphabetic character that was found, example:
RMTS98475
But the issue is that I don't know witch characters and the position of then!
Thank you,
Elisabete
can anyone help me on this issue:
I have this string: RM1246873TS98475
and I want that concatenate WS to the next alphabetic character that was found, example:
RMTS98475
But the issue is that I don't know witch characters and the position of then!
Thank you,
Elisabete
-
- Premium Member
- Posts: 1735
- Joined: Thu Mar 01, 2007 5:44 am
- Location: Troy, MI
Which version of datastage you are using?
Also please provide more details on the problem. Will there be only two two character strings will be there, what needs to be done if there are more than 2 of the same. Also if there are more scenarios to be covered, provide examples.
Also please provide more details on the problem. Will there be only two two character strings will be there, what needs to be done if there are more than 2 of the same. Also if there are more scenarios to be covered, provide examples.
Priyadarshi Kunal
Genius may have its limitations, but stupidity is not thus handicapped.![Wink :wink:](./images/smilies/icon_wink.gif)
Genius may have its limitations, but stupidity is not thus handicapped.
![Wink :wink:](./images/smilies/icon_wink.gif)
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
"WS" or "TS"?
If it's always two characters then an approach using substring would be the most efficient. For example:
If it's always two characters then an approach using substring would be the most efficient. For example:
Code: Select all
InLink.TheString[1,2] : "TS" : InLink.TheString[3,Len(InLink.TheString)-2]
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.
-
- Premium Member
- Posts: 1735
- Joined: Thu Mar 01, 2007 5:44 am
- Location: Troy, MI
Yes, Vamsi.4a6 is correct
as I see the examples the first two places has the first string, you need to find the second one and then concatanate the first two with everything else after you encounter the 3rd character. In that case you can use the following derivation. Also I prefer to perform index(convert()) in a stage variable and use the output in below code.
as I see the examples the first two places has the first string, you need to find the second one and then concatanate the first two with everything else after you encounter the 3rd character. In that case you can use the following derivation. Also I prefer to perform index(convert()) in a stage variable and use the output in below code.
Code: Select all
InLink.TheString[1,2]:InLink.TheString[index(convert('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz','#',InLink.TheString),'#',3),len(InLink.TheString) - index(convert('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz','#',InLink.TheString),'#',3)]
Priyadarshi Kunal
Genius may have its limitations, but stupidity is not thus handicapped.![Wink :wink:](./images/smilies/icon_wink.gif)
Genius may have its limitations, but stupidity is not thus handicapped.
![Wink :wink:](./images/smilies/icon_wink.gif)
SMALL MODIFICATION IN DERIVATION
InLink.TheString[1,2]:InLink.TheString[index(convert('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz','#',InLink.TheString),'#',3),len(InLink.TheString) - index(convert('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz','#',InLink.TheString),'#',3)+1]
Please correct me if i am wrong
ex-RM124TS984
index(convert('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz','#',InLink.TheString),'#',3) WILL GIVE 6
len(InLink.TheString)- WILL GIVE 10
index(convert('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz','#',InLink.TheString),'#',3)-WILL GIVE 6
SO InLink.TheString[6,10-6] WILL EXTRACT ONLY FOUR CHARACTERS SO WE NEED TO ADD +1 TO IT
InLink.TheString[1,2]:InLink.TheString[index(convert('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz','#',InLink.TheString),'#',3),len(InLink.TheString) - index(convert('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz','#',InLink.TheString),'#',3)+1]
Please correct me if i am wrong
ex-RM124TS984
index(convert('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz','#',InLink.TheString),'#',3) WILL GIVE 6
len(InLink.TheString)- WILL GIVE 10
index(convert('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz','#',InLink.TheString),'#',3)-WILL GIVE 6
SO InLink.TheString[6,10-6] WILL EXTRACT ONLY FOUR CHARACTERS SO WE NEED TO ADD +1 TO IT
-
- Premium Member
- Posts: 1735
- Joined: Thu Mar 01, 2007 5:44 am
- Location: Troy, MI
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
There's a very elegant solution if you're prepared to use the BASIC Transformer stage (or a server Transformer in a server Shared Container in your parallel job, or a server job). You can use server pattern matching via the MatchField() function, and delimited field replacement via the FieldStore() function.
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.
Re: Find the character in a string
Try using FIELD function with delimiter string as "TS"
Lather you can concatenate 2nd part of your string for the concatenation
Ex.
Link.Column[1,2]:FIELD[Link.Column,"TS",2]
Let me know if it works out...
Lather you can concatenate 2nd part of your string for the concatenation
Ex.
Link.Column[1,2]:FIELD[Link.Column,"TS",2]
Let me know if it works out...
Rahul
DS Lover
DS Lover