"replace" (string::replace)

Replaces part of a string with a new one.

Synopsis

int string.replace(int pos, int n, string after);

int string.replace(string before, string after);

Parameters

Parameter Description
pos Starting position
n Number of characters
after Replacement string
before Original string to be replaced

Description

Replaces n characters beginning at index pos with the string after.

If the specified pos index is within the string, but pos + n goes outside the strings range, then n will be adjusted to stop at the end of the string.

Alternatively, the original string you want to replace can be directly used as a parameter in the function.

main()
{
  string test = "This\nis\na\nTest!";
  DebugTN("before", test); 
  test.replace("\n", " "); 
  DebugTN("after", test);
}               

Console output:

WCCOAui1:2023.06.29 13:33:20.598["before"]["This
WCCOAui1:is
WCCOAui1:a
WCCOAui1:Test!"]
WCCOAui1:2023.06.29 13:33:20.598["after"]["This is a Test!"]               

Assignment

String