pure functionsubstring
Return a substring defined by start and end index
Extends from Modelica.Icons.Function (Icon for functions).
Information
Syntax
string2 = Strings.substring(string, startIndex, endIndex);
Description
This function returns the substring from position startIndex up to and including position endIndex of "string" . The substring computation has the following properties:
- If the
startIndexis non-positive, it is set to 1 and a warning is raised. - If the
startIndexexceeds the string length, the returned substring is empty. - If the
endIndexis negative, it is set to thestartIndexand a warning is raised. The returned substring is the single character at positionstartIndexofstring. - If the
endIndexis non-negative and less than thestartIndex, the returned substring is empty. - If the
endIndexexceeds the string length, it is set to the string length. - It is only intended for ASCII encoded strings. For UTF-8 encoded strings the index is seen as bytes, and some index values may break the string inside glyphs or even inside code points.
Example
string1 := "This is line 111"; string2 := Strings.substring(string1,9,12); // string2 = "line" string3 := Strings.substring(string1,9,0); // string3 = ""
Inputs
| Type | Name | Default | Description |
|---|---|---|---|
| String | string | String from which a substring is inquired | |
| Integer | startIndex | Character position of substring begin (index=1 is first character in string) | |
| Integer | endIndex | Character position of substring end |
Outputs
| Type | Name | Default | Description |
|---|---|---|---|
| String | result | String containing substring string[startIndex:endIndex] |