I would like to replace first 0 with two other digits in AMPscript
E.g. 0123012345
I would like this to be 98123012345
I've tried substring/replace but it looks for all 0s in the number and does not output expected.
Thanks,
Not sure I fully understand your use case, but this will work if you want to trim the 0
just if the string starts with 0
and replace it with 98:
%%[
var @num, @repl
set @num = "0123012345"
if indexOf(@num, "0") == 1 then
set @repl = Concat("98",Substring(@num,2,Length(@num)))
endif
]%%
number: %%=v(@num)=%%
<br>
replaced: %%=v(@repl)=%%
Above will output:
number: 0123012345
replaced: 98123012345
if indexOf(@num, "0") == 1
which checks if the position of 0
is 1 which means that it's the first character of the string.
Commented
Aug 13, 2020 at 7:19