Need to Insert a character in a string at particular positio

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
deepa.y
Participant
Posts: 56
Joined: Mon Nov 28, 2011 10:47 pm
Location: Bangalore

Need to Insert a character in a string at particular positio

Post by deepa.y »

Hi,
I have an input string "AAABCCDEK".I want to insert a character '^' at 4th and 8th position of the string using transformer stage.
My output should look like this "AAA^BCC^DEK".
Can somebody help me out in this logic?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Assuming the string is exactly nine characters long:

Code: Select all

InLink.TheString[1,3] : "^" : InLink.TheString[4,3] : "^" : InLink.TheString[7,3]
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
deepa.y
Participant
Posts: 56
Joined: Mon Nov 28, 2011 10:47 pm
Location: Bangalore

Post by deepa.y »

The length of input string will vary but position of characters to be inserted will be at 4th and 8th only.
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Post by pandeesh »

So you need to len() function also:

Code: Select all

InLink.TheString[1,3] : "^" : InLink.TheString[4,3] : "^" : InLink.TheString[7,len(InLink.TheString)-6]
pandeeswaran
deepa.y
Participant
Posts: 56
Joined: Mon Nov 28, 2011 10:47 pm
Location: Bangalore

Post by deepa.y »

Thanks Ray
Thanks Pandeesh
That worked fine.
I am resolving this topic
pandeesh
Premium Member
Premium Member
Posts: 1399
Joined: Sun Oct 24, 2010 5:15 am
Location: CHENNAI, TAMIL NADU

Post by pandeesh »

Welcome!!
pandeeswaran
Post Reply