String functions support extraction, concatenation, case conversion, regular expression matching, splitting, and formatting of string values.
substr
| Feature | Description |
| Syntax | substr(s, i, j) |
| Description | Extracts parts from a string. |
| Parameter |
|
| Return value | Returns a substring s[i, j] from the source string s. |
| Example | |
concat
| Feature | Description |
| Syntax | concat(s1, ...) |
| Description | Concatenates strings. |
| Parameter | The strings that you want to concatenate. You can specify one or more strings. Numeric values are supported. |
| Return value | Returns a concatenated string. |
| Example | |
upper
| Feature | Description |
| Syntax | upper(s) |
| Description | Converts a string to uppercase letters. |
| Parameter | s: the string that you want to convert. |
| Return value | Returns the s string in uppercase. |
| Example | |
lower
| Feature | Description |
| Syntax | lower(s) |
| Description | Converts a string to lowercase letters. |
| Parameter | s: the string that you want to convert. |
| Return value | Returns the s string in lowercase. |
| Example | |
len
| Feature | Description |
| Syntax | len(s) |
| Description | Queries the length of a string. |
| Parameter | s: the string that you want to measure. |
| Return value | Returns the length of the s string. Data type: integer. |
| Example | |
byte
| Feature | Description |
| Syntax | byte(c) |
| Description | Queries the ASCII value of a character. |
| Parameter | c: the character whose ASCII value you want to query. You can specify only one character. |
| Return value | Returns the ASCII value of the specified character. Data type: numeric. |
| Example | |
match_re
| Item | Description |
| Syntax | match_re(s, p [, o]). |
| Description | Checks if a string matches a regular expression. This function uses the PCRE regular expression engine. For more information, see PCRE syntax. |
| Parameter |
|
| Return value | Returns true if the string matches the pattern, and false otherwise. |
| Example | |
capture_re
| Feature | Description |
| Syntax | capture_re(s, p [,init]) |
| Description | Captures the matches of a string and returns the matching substrings. For more information about PCRE, see PCRE syntax. |
| Parameter |
|
| Return value | Returns the matching substrings as a dictionary if the pattern matches, or an empty dictionary otherwise. |
| Example | |
gsub_re
| Feature | Description |
| Syntax | gsub_re(subject, regex, replace [,option]) |
| Description | Replaces all matches of a string and returns the string after the replacement. For more information about PCRE, see PCRE syntax. |
| Parameter |
|
| Return value | Returns the string after replacing all regex matches in subject with replace. |
| Example | |
split
| Feature | Description |
| Syntax | split(s [,sep]) |
| Description | Splits a string into an array of substrings and returns the array. |
| Parameter |
|
| Return value | Returns an array of key-value pairs in the dictionary type. The value of the key parameter is a number that starts from 1, for example, [1]=xx and [2]=y. If sep is left empty, the string is split by whitespace characters. Whitespace characters include space characters and tab characters (\t). |
| Example | |
split_as_key
| Feature | Description |
| Syntax | split_as_key(s [,sep]) |
| Description | Splits a string into an array of substrings and returns the array. |
| Parameter |
|
| Return value | Returns response parameters in the same way as the split() function. However, the key parameter is named after each split element: Element 1 -> Element 2. |
| Example | |
tohex
| Feature | Description |
| Syntax | tohex(s) |
| Description | Converts a string to a hexadecimal string. |
| Parameter | s: the string that you want to convert. |
| Return value | Returns a hexadecimal string converted from s. |
| Example | |
tostring
| Feature | Description |
| Syntax | tostring(a) |
| Description | Converts data of any type to a string. |
| Parameter | a: the data that you want to convert. Data type: any type. |
| Return value | Returns a string converted from the a value. |
| Example | |
tochar
| Feature | Description |
| Syntax | tochar(n1, n2, ...) |
| Description |
|
| Parameter | nX: the integers that you want to convert. You can specify one or more integers. |
| Return value | Returns a string converted from integers. |
| Example | |
reverse
| Feature | Description |
| Syntax | reverse(str) |
| Description | Reverses a string. |
| Parameter | str: the string that you want to reverse. |
| Return value | Returns the reversed string. |
| Example | Output: |
find
| Feature | Description |
| Syntax | string.find (s, substr, pos) |
| Description | Searches for a substring in a specified string. |
| Parameter |
|
| Return value |
|
| Example | Output: |
format
| Feature | Description |
| Syntax | format(fmt, ···) |
| Description | Formats values according to a format string. The format string is the first parameter and must be a string. It follows the sprintf specification from the C programming language. The syntax of a format string is: %[parameter][flag][field width][.precision]specifier.
|
| Parameter |
|
| Return value | Returns an ASCII string. |
| Example | Output: |
tobin
| Feature | Description |
| Syntax | tobin(str) |
| Description | Converts a hexadecimal string to an ASCII string. |
| Parameter | str: the hexadecimal string that you want to convert. It is not case-sensitive. |
| Return value | Returns an ASCII string. |
| Example | Output: |
trim
| Feature | Description |
| Syntax | trim(s, [, loc]) |
| Description | Removes whitespace characters before and/or after a string. |
| Parameter |
|
| Return value | Returns the trimmed string. |
| Example | Output: |