This topic describes the syntax, features, parameters, and return values of string functions. This topic also provides examples of these functions.
substr | concat | format | upper | lower | len | byte | match_re | capture_re | gsub_re | split | split_as_key | tohex | tobin | tostring | tochar | reverse | find | trim
substr
Item | Description |
---|---|
Syntax | substr(s, i, j) |
Description | Extracts a substring from a string. |
Parameter |
|
Return value | A substring s[i, j] that is extracted from the source string specified by s is returned. |
Example | You can use the following methods to determine whether a file is an M3U8 file:
|
concat
Item | 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 | A concatenated string. |
Example | You can use the following methods to determine whether a file is an M3U8 file:
|
format
Item | 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 ISO C programming language. The syntax of a format string specified by fmt is %[parameter][flag][field width][precision]specifier .
|
Parameter |
|
Return value | A string. |
Example | Output:
|
upper
Item | Description |
---|---|
Syntax | upper(s) |
Description | Converts a string to uppercase letters. |
Parameter | s: the string that you want to convert. |
Return value | The string specified by the s parameter in uppercase letters. |
Example | Output:
|
lower
Item | Description |
---|---|
Syntax | lower(s) |
Description | Converts a string to lowercase letters. |
Parameter | s: the string that you want to convert. |
Return value | The string specified by the s parameter in lowercase letters. |
Example | Output:
|
len
Item | Description |
---|---|
Syntax | len(s) |
Description | Queries the length of a string. |
Parameter | s: the string that you want to query. |
Return value | The length of the string specified by the s parameter. Data type: integer. |
Example | You can use the following methods to determine whether a file is an M3U8 file:
|
byte
Item | 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 | The ASCII value of the specified character. Data type: numeric. |
Example | Output:
|
match_re
Item | 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
Item | 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 | If the string matches the regular expression, the matching substrings in the dictionary type are returned. Otherwise, an empty dictionary is returned. |
Example |
|
gsub_re
Item | 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 | The function 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 | Output:
|
split
Item | Description |
---|---|
Syntax | split(s [,sep]) |
Description | Splits a string into an array of substrings and returns the array. |
Parameter |
|
Return value | 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, [2]=yy. If sep is left empty, the string is split by whitespace characters. Whitespace characters include space characters and tab characters (\t). |
Example |
Request:
Response:
|
split_as_key
Item | Description |
---|---|
Syntax | split_as_key(s [,sep]) |
Description | Splits a string into an array of substrings and returns the array. |
Parameter |
|
Return value | Response parameters are returned in the same way as the split() function. However, the key parameter is named after each split element: Element 1 -> Element 2 . |
Example |
Request:
Response:
|
tohex
Item | Description |
---|---|
Syntax | tohex(s) |
Description | Converts a string to a hexadecimal string. |
Parameter | s: the string that you want to convert. |
Return value | A hexadecimal string that is converted from the string specified by the s parameter. |
Example | Output:
|
tobin
Item | 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 | A string. |
Example | Output:
|
tostring
Item | 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 | A string that is converted from the value specified by the a parameter. |
Example | Output:
|
tochar
Item | Description |
---|---|
Syntax | tochar(n1, n2, ...) |
Description |
|
Parameter | nX: the integers that you want to convert. You can specify one or more integers. |
Return value | A string that is converted from integers. |
Example |
Output: A response header is added
|
reverse
Item | Description |
---|---|
Syntax | reverse(str) |
Description | Reverses a string. |
Parameter | str: the string that you want to reverse. |
Return value | A string reversed from the specified string. Data type: CHAR. |
Example | Output:
|
find
Item | Description |
---|---|
Syntax | string.find (s, substr, pos) |
Description | Searches for a substring in a specified string. |
Parameter |
|
Return value |
|
Example | Output:
|
trim
Item | Description |
---|---|
Syntax | trim(s, [, loc]) |
Description | Removes all whitespace characters at the beginning or at the end of the string specified by the s parameter, and returns a string with the specified whitespace characters removed. |
Parameter |
|
Return value | A string with the specified whitespace characters removed. |
Example | Output:
|