Class Reference string

The string class provides a Unicode character string. More...

Member

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()

Detailed Description

graph LR sl(stringList)--at-->s(string) e(element)--getName-->s f(file)--read-->s click sl "/layoutscript/api/stringlist" click e "/layoutscript/api/element" click f "/layoutscript/api/file" click s "/layoutscript/api/string" classDef thisClas fill:#eaf5fc,stroke:#3c7faa,stroke-width:4px; classDef clas fill:#eaf5fc,stroke:#3c7faa,stroke-width:1px; class s thisClas class sl,e,f clas

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(" ");

Member Function Documentation


string::string( )

Creates a new empty string.


string::string(string item)

Creates a string containing a copy of item.


bool string::contains(string item)

Returns: true if this string contains item, otherwise false.


int string::indexOf(string str, int index)

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

void string::jsonInsert(string key, string value)

Parses this string as JSON and sets the key / value pair.

Parameter:
key key index or code
value value

stringList string::jsonKeys(string key)

Parses this string as JSON and returns the keys of the object named key.

Returns: a stringList of keys.


string string::jsonValue(string key)

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.


int string::lastIndexOf(string str, int index)

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

string string::left(int left)

Returns: the first left characters of the string.


int string::length()

Returns: the length of the string, identical to size.


string string::mid(int position, int length=-1)

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.


string string::parameter(string str)

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";

string string::remove(string str)

Removes every occurrence of str. The search is case sensitive.

Returns: the string after removal.


string string::removeNonAscii()

Removes all non-ASCII characters. (introduced 20201011)

Returns: the string after removal.


string string::replace(string macht,string with)

Replaces every occurrence of macht with with. The replacement is case sensitive.

Returns: the string after replacement.

Parameter:
macht macht
with with

string string::right(int right)

Returns: the last right characters of the string.


string string::setDate(string format="")

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.


string string::setDateTime(string format="")

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.


string string::setEng(double value)

Sets the string to value in engineering notation, such as 10k.

Returns: this string after it was set.


string string::setHex(int hex-number)

Sets the string to hex-number as a hexadecimal value.

Returns: this string after it was set.


string string::setNum(double value, int precision)

Sets the string to value with precision digits.

Returns: this string after it was set.


string string::setNum(int number)

Sets the string to number.

Returns: this string after it was set.


string string::setTime(string format="")

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.


int string::size()

Returns: the length of the string (same as length).


stringList string::split(string s)

Splits this string on separator s.

Returns: a stringList of the parts.


double string::toDouble()

Returns: this string converted to a double.


double string::toDoubleFromEng()

Returns: this string converted to a double, including engineering notation such as 10.6k or 7.3n.


int string::toInt()

Returns: this string converted to an integer.


string string::toLower()

Returns: a lowercase copy of the string.


string string::toUpper()

Returns: an uppercase copy of the string.


string string::trimmed()

Returns: a copy with whitespace removed from the start and the end.