Page 1 of 1

Replace only first and last occurence of a string

Posted: Tue Aug 23, 2011 6:08 am
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

Posted: Tue Aug 23, 2011 6:19 am
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