(* how to transform “abc2” into “abc3” ? *)
string = "abc2";
regex = ".$";
newString =
StringReplace[string,
RegularExpression[regex] -> IntegerString[1+$0 ]]
(* output expected: “abc3” - but output is:
"abc"~~IntegerString[1+$0]
*)
(* how to transform “abc2” into “abc3” ? *)
string = "abc2";
regex = ".$";
newString =
StringReplace[string,
RegularExpression[regex] -> IntegerString[1+$0 ]]
(* output expected: “abc3” - but output is:
"abc"~~IntegerString[1+$0]
*)
In[1]:= string = “abc2”;
In[2]:= StringJoin[StringDrop[string, {4}],
ToString[(ToExpression@StringPart[string, 4] + 1)]]
Out[2]= "abc3"
(* solved:
:> not → ,the latter,Rule,is evaluated immediately *)
string = “abc2”;
regex = “.$”;
newString =
StringReplace[string,
RegularExpression[regex] :> ToString[1 + FromDigits[“$0”]]]
(* output is:
“abc3”
*)