Removing and Replacing Characters in Strings in X++

Sometimes you will need to either remove or replace characters in a string:

To replace:

strreplace("Hello", "l", "p"); // returns "Heppo"

And to remove:

strrem("Hello", "l"); // returns "Heo"

Something to keep in mind:


str stringVariable = "Hello";
;
strreplace(stringVariable, "l", "p");
info(strfmt("%1", stringVariable)); // --> prints "Hello"
stringVariable = strreplace(stringVariable, "l", "p"); 
info(strfmt("%1", stringVariable)); // --> prints "Heppo"

This is the same for ‘strrem()’, any string operations performed on variables will need to be done through assignment if your intention is to change the variable’s value.