I would like to replace first 0 with two other digits in AMPscript E.g. 0123012345I 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.


1 Answer 1


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)))


number: %%=v(@num)=%%
replaced: %%=v(@repl)=%%

Above will output:

number: 0123012345
replaced: 98123012345
  • hI @zuzannamj, from my understanding the index of looks for 0 in any position of the string. Is there way to check if the string starts with 0 and set repl variable if it does?
    – s3002068
    Aug 13, 2020 at 7:17
  • 2
    That's exactly what I did :-) I've added a condition 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.
    – zuzannamj
    Aug 13, 2020 at 7:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .