.Modelica.Utilities.Strings

Information

Library content

Package Strings contains functions to manipulate strings.

In the table below an example call to every function is given using the default options.

FunctionDescription
len = length(string) Returns length of string
string2 = substring(string1,startIndex,endIndex) Returns a substring defined by start and end index
result = repeat(n)
result = repeat(n,string)
Repeat a blank or a string n times.
result = compare(string1, string2) Compares two substrings with regards to alphabetical order
identical = isEqual(string1,string2) Determine whether two strings are identical
result = count(string,searchString) Count the number of occurrences of a string
index = find(string,searchString) Find first occurrence of a string in another string
index = findLast(string,searchString) Find last occurrence of a string in another string
string2 = replace(string,searchString,replaceString) Replace one or all occurrences of a string
stringVector2 = sort(stringVector1) Sort vector of strings in alphabetic order
hash = hashString(string) Create a hash value of a string
(token, index) = scanToken(string,startIndex) Scan for a token (Real/Integer/Boolean/String/Identifier/Delimiter/NoToken)
(number, index) = scanReal(string,startIndex) Scan for a Real constant
(number, index) = scanInteger(string,startIndex) Scan for an Integer constant
(boolean, index) = scanBoolean(string,startIndex) Scan for a Boolean constant
(string2, index) = scanString(string,startIndex) Scan for a String constant
(identifier, index) = scanIdentifier(string,startIndex) Scan for an identifier
(delimiter, index) = scanDelimiter(string,startIndex) Scan for delimiters
scanNoToken(string,startIndex) Check that remaining part of string consists solely of
white space or line comments ("// ...\n").
syntaxError(string,index,message) Print a "syntax error message" as well as a string and the
index at which scanning detected an error

The functions "compare", "isEqual", "count", "find", "findLast", "replace", "sort" have the optional input argument caseSensitive with default true. If false, the operation is carried out without taking into account whether a character is upper or lower case.

Contents

NameDescription
 lengthReturn length of string
 substringReturn a substring defined by start and end index
 repeatRepeat a string n times
 compareCompare two strings lexicographically
 isEqualDetermine whether two strings are identical
 isEmptyReturn true if a string is empty (has only white space characters)
 countCount the number of non-overlapping occurrences of a string
 findFind first occurrence of a string within another string
 findLastFind last occurrence of a string within another string
 replaceReplace non-overlapping occurrences of a string from left to right
 sortSort vector of strings in alphabetic order
 hashStringCreate a hash value of a string
 scanTokenScan for the next token and return it
 scanRealScan for the next Real number and trigger an assert if not present
 scanIntegerScan for the next Integer number and trigger an assert if not present
 scanBooleanScan for the next Boolean number and trigger an assert if not present
 scanStringScan for the next Modelica string and trigger an assert if not present
 scanIdentifierScan for the next Identifier and trigger an assert if not present
 scanDelimiterScan for the next delimiter and trigger an assert if not present
 scanNoTokenScan string and check that it contains no more token
 syntaxErrorPrint an error message, a string and the index at which scanning detected an error
 AdvancedAdvanced scanning functions

Generated at 2024-12-23T19:25:42Z by OpenModelicaOpenModelica 1.24.3 using GenerateDoc.mos