functionreplace

Replace non-overlapping occurrences of a string from left to right

Extends from Modelica.Icons.Function (Icon for functions).

Information

Syntax

Strings.replace(string, searchString, replaceString);
Strings.replace(string, searchString, replaceString,
                startIndex=1, replaceAll=true, caseSensitive=true);

Description

Search in "string" for "searchString" and replace the found substring by "replaceString".

  • The search starts at the first character of "string", or at character position "startIndex", if this optional argument is provided.
  • If the optional argument "replaceAll" is true (default), all occurrences of "searchString" are replaced. If the argument is false, only the first occurrence is replaced.
  • The search for "searchString" distinguishes upper and lower case letters. If the optional argument "caseSensitive" is false, the search ignores whether letters are upper or lower case.
  • It is intended for ASCII. The case-insensitive search is not guaranteed to work for UTF-8.

The function returns the "string" with the performed replacements.

Inputs

TypeNameDefaultDescription
StringstringString to be modified
StringsearchStringReplace non-overlapping occurrences of 'searchString' in 'string' with 'replaceString'
StringreplaceStringString that replaces 'searchString' in 'string'
IntegerstartIndex1Start search at index startIndex
BooleanreplaceAlltrue= false, if only the first occurrence is replaced, otherwise all occurrences
BooleancaseSensitivetrue= false, if lower and upper case are ignored when searching for searchString

Outputs

TypeNameDefaultDescription
StringresultResultant string of replacement operation