Find the character in a string

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

Post Reply
Elisabete
Participant
Posts: 17
Joined: Mon Jan 03, 2011 7:55 am
Location: Odivelas

Find the character in a string

Post by Elisabete »

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
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

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.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
Elisabete
Participant
Posts: 17
Joined: Mon Jan 03, 2011 7:55 am
Location: Odivelas

Post by Elisabete »

The version of datastage is: 8.1.

There no more scenarios, only this one, and yes are only two alphabetic characters.

you can help me?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

"WS" or "TS"?

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.
Elisabete
Participant
Posts: 17
Joined: Mon Jan 03, 2011 7:55 am
Location: Odivelas

Post by Elisabete »

but I don't know the position of the second alphabetic characters... this string is just a example... it can be in many ways:

RM1246873TS98475
RM12473TS98475
RM12473TS984

NOTE: I can't read premium posts!
vamsi.4a6
Participant
Posts: 334
Joined: Sun Jan 22, 2012 7:06 am
Contact:

Post by vamsi.4a6 »

1)use convert function to replace some dummy character say # for all the alphabets
2)use index function to find the position of third occurrence of # and then perform substring and concatenation
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

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.

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:
vamsi.4a6
Participant
Posts: 334
Joined: Sun Jan 22, 2012 7:06 am
Contact:

Post by vamsi.4a6 »

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
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

yes, you are correct vamsi, I missed adding 1 to it.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
Kryt0n
Participant
Posts: 584
Joined: Wed Jun 22, 2005 7:28 pm

Post by Kryt0n »

Think Ray's point is that if you are always looking for TS then just find the index of TS. (and/or WS if that is a potential)
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

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.
rahcomp
Participant
Posts: 11
Joined: Wed Apr 18, 2012 2:13 pm

Re: Find the character in a string

Post by rahcomp »

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...
Rahul
DS Lover
Post Reply