Replace only first and last occurence of a string

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
mac4rfree85
Participant
Posts: 126
Joined: Thu Jul 01, 2010 11:39 pm

Replace only first and last occurence of a string

Post by mac4rfree85 »

Hi Guys,

I want to replace only the first and last occurance of a string.

For the first occurance i am using Ereplace command.

Code: Select all

Ereplace(colname,"A",'')
But i am not able to find out how to do it for the last occurance.

Code: Select all

I/P :  dbklasasaaada
O/P : dbklsasaaad
Cheers
Mac4rfree
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

There's no single function. Use If..Then..Else to test whether the rightmost character is the one you want to change then, if it is, concatenate the replacement character to the string without its original rightmost character.

Code: Select all

If Right(InLink.TheString,1) = "X" Then Left(InLink.TheString,Len(InLink.TheString)-1) : "Y" Else InLink.TheString
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply