The string class provides a Unicode character string. More...
| string( ) | |
| string(string item) | |
| bool | contains(string item) |
| int | indexOf(string str, int index) |
| void | jsonInsert(string key, string value) |
| stringList | jsonKeys(string key) |
| string | jsonValue(string key) |
| int | lastIndexOf(string str, int index) |
| string | left(int left) |
| int | length() |
| string | mid(int position, int length=-1) |
| string | parameter(string str) |
| string | remove(string str) |
| string | removeNonAscii() |
| string | replace(string macht,string with) |
| string | right(int right) |
| string | setDate(string format="") |
| string | setDateTime(string format="") |
| string | setEng(double value) |
| string | setHex(int hex-number) |
| string | setNum(double value, int precision) |
| string | setNum(int number) |
| string | setTime(string format="") |
| int | size() |
| stringList | split(string s) |
| double | toDouble() |
| double | toDoubleFromEng() |
| int | toInt() |
| string | toLower() |
| string | toUpper() |
| string | trimmed() |
A string is the Unicode text type used in LayoutEditor C++ macros. You construct one, or receive it from element getName, file read, or stringList at. length and size are the character count; left, right, and mid take slices; contains, indexOf, and lastIndexOf search. split yields a stringList; parameter reads key=value fields; jsonValue, jsonKeys, and jsonInsert treat the text as JSON. setNum, setEng, toInt, and toDoubleFromEng convert numbers, including engineering suffixes such as 10k. In Python this class is not used: the language's own string type is mapped instead.
Example:
string s = "type=2 width=4 length=6";
string w = s.parameter("width");
s.setNum(12);
s = s + " um";
stringList parts = s.split(" ");
Creates a new empty string.
Creates a string containing a copy of item.
Returns: true if this string contains item, otherwise false.
Returns: the index of the first occurrence of str, searching forward from index. Returns -1 if str is not found.
| Parameter: | |
|---|---|
| str | str |
| index | index |
Parses this string as JSON and sets the key / value pair.
| Parameter: | |
|---|---|
| key | key index or code |
| value | value |
Parses this string as JSON and returns the keys of the object named key.
Returns: a stringList of keys.
Parses this string as JSON and returns the value of key. An empty string is returned if the JSON does not contain that key.
Returns: the value as a string.
Returns: the index of the last occurrence of str, searching backward from index. If index is -1, the search starts at the last character; if -2, at the next-to-last character, and so on. Returns -1 if str is not found.
| Parameter: | |
|---|---|
| str | str |
| index | index |
Returns: the first left characters of the string.
Returns: the length of the string, identical to size.
Returns: the substring that starts at position and has length characters. The rest of the string from position is returned if length is -1 or omitted.
Returns: the value of parameter str in a key=value list.
Example:
string s="type=2 width=4 length=6";
s=s.parameter("width");
// s="4";
Removes every occurrence of str. The search is case sensitive.
Returns: the string after removal.
Removes all non-ASCII characters. (introduced 20201011)
Returns: the string after removal.
Replaces every occurrence of macht with with. The replacement is case sensitive.
Returns: the string after replacement.
| Parameter: | |
|---|---|
| macht | macht |
| with | with |
Returns: the last right characters of the string.
Sets the string to the current date. format selects the pattern; without it the local setup is used. See setDateTime for possible formats.
Returns: this string after it was set.
Sets the string to the current date and time. format selects the pattern; without it the local setup is used.
The format string may contain:
| Expression | Output |
|---|---|
| d | the day as number without a leading zero (1 to 31) |
| dd | the day as number with a leading zero (01 to 31) |
| ddd | the abbreviated localized day name (e.g. 'Mon' to 'Sun'). |
| dddd | the long localized day name (e.g. 'Qt::Monday' to 'Qt::Sunday'). |
| M | the month as number without a leading zero (1-12) |
| MM | the month as number with a leading zero (01-12) |
| MMM | the abbreviated localized month name (e.g. 'Jan' to 'Dec'). |
| MMMM | the long localized month name (e.g. 'January' to 'December'). |
| yy | the year as two digit number (00-99) |
| yyyy | the year as four digit number (1752-8000) |
| h | the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display) |
| hh | the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display) |
| m | the minute without a leading zero (0 to 59) |
| mm | the minute with a leading zero (00 to 59) |
| s | the second without a leading zero (0 to 59) |
| ss | the second with a leading zero (00 to 59) |
| z | the milliseconds without leading zeroes (0 to 999) |
| zzz | the milliseconds with leading zeroes (000 to 999) |
| AP | use AM/PM display. AP will be replaced by either "AM" or "PM". |
| ap | use am/pm display. ap will be replaced by either "am" or "pm". |
Returns: this string after it was set.
Sets the string to value in engineering notation, such as 10k.
Returns: this string after it was set.
Sets the string to hex-number as a hexadecimal value.
Returns: this string after it was set.
Sets the string to value with precision digits.
Returns: this string after it was set.
Sets the string to number.
Returns: this string after it was set.
Sets the string to the current time. format selects the pattern; without it the local setup is used. See setDateTime for possible formats.
Returns: this string after it was set.
Returns: the length of the string (same as length).
Splits this string on separator s.
Returns: a stringList of the parts.
Returns: this string converted to a double.
Returns: this string converted to a double, including engineering notation such as 10.6k or 7.3n.
Returns: this string converted to an integer.
Returns: a lowercase copy of the string.
Returns: an uppercase copy of the string.
Returns: a copy with whitespace removed from the start and the end.