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
| Type | Name | Default | Description |
|---|---|---|---|
| String | string | String to be modified | |
| String | searchString | Replace non-overlapping occurrences of 'searchString' in 'string' with 'replaceString' | |
| String | replaceString | String that replaces 'searchString' in 'string' | |
| Integer | startIndex | 1 | Start search at index startIndex |
| Boolean | replaceAll | true | = false, if only the first occurrence is replaced, otherwise all occurrences |
| Boolean | caseSensitive | true | = false, if lower and upper case are ignored when searching for searchString |
Outputs
| Type | Name | Default | Description |
|---|---|---|---|
| String | result | Resultant string of replacement operation |