Page 1 of 1

Replace

Posted: Wed Feb 09, 2011 4:03 am
by saj
Hi ,
I have a requirement for replacing a substr strting from 10th to 13th.
Ex:
Ad12345678301ATI

I need to replace the value starting from 10th position to 13th
In the above case 301 with 812.
please help .
Is it possible to do this with Ereplace .

Posted: Wed Feb 09, 2011 8:16 am
by chulett
Substring using the "[]" operators:

Code: Select all

YourString[1,9]:"XXXX":YourString[13,999]
Where "XXXX" is the replacement text for string positions 10 thru 12.

Edited because you actually meant 10th thru 12th. :?

Posted: Wed Feb 09, 2011 11:14 am
by ray.wurlod
It is easily possible to do this with Ereplace() if that's the only occurrence of 301 in the data, otherwise you'd have to do some more manipulation to determine which occurrence of 301 to replace. Replacing the substring is likely to be a lot easier.

Code: Select all

InLink.TheString[1,9] : "801" : InLink.TheString[13,999999]

Posted: Wed Feb 09, 2011 1:04 pm
by saj
ray.wurlod wrote:It is easily possible to do this with Ereplace() if that's the only occurrence of 301 in the data, otherwise you'd have to do some more manipulation to determine which occurrence of 301 to replace. R ...
Hi Ray,
Could you please let me know how to use with Ereplace since there will be multiple occurrence in the string .

Posted: Wed Feb 09, 2011 6:09 pm
by chulett
Quite simple to substring instead, as already suggested.

Posted: Wed Feb 09, 2011 10:33 pm
by ray.wurlod
chulett wrote:Quite simple to substring instead, as already suggested.
... only with the internal looping feature in version 8.5, since there are multiple occurrences.

To use pxEreplace() - assuming you've installed and compiled it, etc. -

Code: Select all

pxEreplace(InLink.TheString, "301", "801", -1, 0)

Posted: Wed Feb 09, 2011 11:20 pm
by chulett
I was responding to the original question, specifically - replacing the contents of positions 10 thru 12 in the string. One time, one place, hence the suggestion to substring. The OP was wondering how to make the pxEreplace do the same because there can be multiple occurances of the target characters in the string, something you've now answered. Sorta.

However, "301" was (I assume) just one example and (again) I've been assuming the actual need was not for a fixed value but rather regardless of the actual value.