This topic describes the syntax, description, parameters, and return values of string functions. This topic also provides examples of these functions.
substr
The following table describes the details about this function.
Feature | Description |
---|---|
Syntax | substr(s, i, j)
|
Description | Extracts parts from a string. |
Parameter |
|
Return value | Returns a substring s[i, j] that is extracted from the source string specified by s .
|
Example |
|
concat
The following table describes the details about this function.
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
The following table describes the details about this function.
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 string specified by the s parameter in uppercase letters.
|
Example |
|
lower
The following table describes the details about this function.
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 string specified by the s parameter in lowercase letters.
|
Example |
|
len
The following table describes the details about this function.
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 string specified by the s parameter. Data type: integer.
|
Example |
|
byte
The following table describes the details about this function.
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
The following table describes the details about this function.
Feature | Description |
---|---|
Syntax | match_re(s, p [, o])
|
Description | Uses the Perl Compatible Regular Expressions (PCRE) engine for regular expression matching. For more information, see PCRE syntax. |
Parameter |
|
Return value | If the string matches the regular expression, true is returned. Otherwise, false is returned.
|
Example |
|
capture_re
The following table describes the details about this function.
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 in the dictionary type if the string matches the regular expression. Otherwise, an empty dictionary is returned. |
Example |
|
gsub_re
The following table describes the details about this function.
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 | Replaces all substrings that match the specified regex parameter in the specified subject parameter with those specified by the replace parameter and returns the string after the replacement.
|
Example |
|
split
The following table describes the details about this function.
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
The following table describes the details about this function.
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
The following table describes the details about this function.
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 that is converted from the string specified by the s parameter.
|
Example |
|
tostring
The following table describes the details about this function.
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 that is converted from the value specified by the a parameter.
|
Example |
|
tochar
The following table describes the details about this function.
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 that is converted from integers. |
Example |
|
reverse
The following table describes the details about this function.
Feature | Description |
---|---|
Syntax | reverse(str)
|
Description | Reverses a string. |
Parameter | str: the string that you want to reverse. |
Return value | Returns a string reversed from the specified string. |
Example | Output:
|
find
The following table describes the details about this function.
Feature | Description |
---|---|
Syntax | string.find (s, substr, pos)
|
Description | Searches for a substring in a specified string. |
Parameter |
|
Return value |
|
Example | Output:
|
format
The following table describes the details about this function.
Feature | Description |
---|---|
Syntax | format(fmt, ···)
|
Description | Formats the values of one or more parameters. The format string is the first parameter,
which must specify a string. The format string follows the specification of the sprintf
parameter used by functions in the C programming language.
The syntax of a format string is: %[parameter][flag][field width][.precision]specifier.
|
Parameter |
|
Return value | Returns an ACSII string. |
Example | Output:
|
tobin
The following table describes the details about this function.
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 ACSII string. |
Example | Output:
|
trim
The following table describes the details about this function.
Feature | Description |
---|---|
Syntax | trim(s, [, loc])
|
Description | Removes all whitespace characters before or after the string specified by the s parameter, and returns a string with the specified whitespace characters removed. |
Parameter |
|
Return value | Returns a string with the specified whitespace characters removed. |
Example | Output:
|