You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Syntax
set changed = aString.replace(regExpPattern, replacement)
set changed = replace(LITERAL, regExpPattern, replacement)
SemanticsAll strings that correspond to the regular expression pattern will be replaced with the string replacement. If the pattern does not match, the unchanged string will be returned. Returns a new string. The state of the current string is not changed.
SubstitutablesaString, replacement Can be any variable or object attribute having the type String.
regExpPattern Regular expression (see Regular Expressions for a list of valid regular expressions). An introduction into regular expressions can be found at http://www.regular-expressions.info/.
LITERAL String literal.
Examples
set changed = stringSet.s1.replace("X.+", "A"); 

Trimming spaces and whitespaces

If you want to trim leading or trailing spaces or whitespaces of a string, you can use regular expressions in order to remove them.

Trimming leading spaces
set trimmedString = stringSet.s1.replace("^[ ]+", "");
Trimming trailing spaces
set trimmedString = stringSet.s1.replace("[ ]+$", "");
Trimming leading and trailing spaces
set trimmedString = stringSet.s1.replace("^[ ]+|[ ]+$", "");
Trimming leading spaces and whitespaces (\t)
set trimmedString = stringSet.s1.replace("^[ \t]+", "");
  • No labels