string - String Manipulation Functions#
Adapted Air780E Air780EP Air780EPS Air780EQ Air700EAQ Air700EMQ Air700ECQ Air201
Note
This page document is automatically generated by this file. If there is any error, please submit issue or help modify pr, thank you!
Tip
This library has its own demo,click this link to view the demo example of string
string.toHex(str, separator)#
Converts a string HEX
Parameters
Incoming Value Type |
Explanation |
---|---|
string |
String to be converted |
string |
separator, the default is”” |
Return Value
return value type |
explanation |
---|---|
string |
HEX String |
number |
HEX Length of the string |
Examples
string.toHex("\1\2\3") --> "010203" 6
string.toHex("123abc") --> "313233616263" 12
string.toHex("123abc", " ") --> "31 32 33 61 62 63 " 12
string.fromHex(hex)#
Converts HEX to String
Parameters
Incoming Value Type |
Explanation |
---|---|
string |
hex,16 A string composed |
Return Value
return value type |
explanation |
---|---|
string |
String |
Examples
string.fromHex("010203") --> "\1\2\3"
string.fromHex("313233616263") --> "123abc"
string.split(str, delimiter, keepEmtry)#
Split string by specified delimiter
Parameters
Incoming Value Type |
Explanation |
---|---|
string |
Input String |
string |
separator, optional, default “,” |
bool |
Whether to keep blank fragments, the default is false, do not keep firmware available after. 2023.4.11 |
Return Value
return value type |
explanation |
---|---|
table |
Split string table |
Examples
local tmp = string.split("123,233333,122")
log.info("tmp", json.encode(tmp))
local tmp = ("123,456,789"):split(',') --> {'123','456','789'}
log.info("tmp", json.encode(tmp))
-- Keep empty fragments, firmware available after 2023.4.11
local str = "/tmp//def/1234/"
local tmp = str:split("/", true)
log.info("str.split", #tmp, json.encode(tmp))
string.toValue(str)#
Returns the escape string of the string tonumber (used to support conversion of integers over 31 digits.)
Parameters
Incoming Value Type |
Explanation |
---|---|
string |
Input String |
Return Value
return value type |
explanation |
---|---|
string |
The converted binary string |
number |
How many characters were converted |
Examples
string.toValue("123456") --> "\1\2\3\4\5\6" 6
string.toValue("123abc") --> "\1\2\3\a\b\c" 6
string.urlEncode(“123 abc”)#
Convert the string to url encoding.
Parameters
Incoming Value Type |
Explanation |
---|---|
string |
String to be converted |
int |
mode:url Conversion criteria for encoding, |
Return Value
None
Examples
None
string.toBase64(str)#
Base64 Encode a String
Parameters
Incoming Value Type |
Explanation |
---|---|
string |
String to be converted |
Return Value
return value type |
explanation |
---|---|
string |
The decoded string. If decoding fails, an empty string is returned. |
Examples
None
string.fromBase64(str)#
Base64 decoding the string
Parameters
Incoming Value Type |
Explanation |
---|---|
string |
String to be converted |
Return Value
return value type |
explanation |
---|---|
string |
The decoded string. If decoding fails, an empty string is returned. |
Examples
None
string.toBase32(str)#
Base32 encoding the string
Parameters
Incoming Value Type |
Explanation |
---|---|
string |
String to be converted |
Return Value
return value type |
explanation |
---|---|
string |
The decoded string. If decoding fails, a 0-length string is returned. |
Examples
None
string.fromBase32(str)#
Base32 decoding the string
Parameters
Incoming Value Type |
Explanation |
---|---|
string |
String to be converted |
Return Value
return value type |
explanation |
---|---|
string |
The decoded string. If decoding fails, a 0-length string is returned. |
Examples
None
string.startsWith(str, prefix)#
Judgment String Prefix
Parameters
Incoming Value Type |
Explanation |
---|---|
string |
String to check |
string |
Prefix String |
Return Value
return value type |
explanation |
---|---|
bool |
True is true, false is false |
Examples
local str = "abc"
log.info("str", str:startsWith("a"))
log.info("str", str:startsWith("b"))
string.endsWith(str, suffix)#
Judgment String Suffix
Parameters
Incoming Value Type |
Explanation |
---|---|
string |
String to check |
string |
Suffix String |
Return Value
return value type |
explanation |
---|---|
bool |
True is true, false is false |
Examples
local str = "abc"
log.info("str", str:endsWith("c"))
log.info("str", str:endsWith("b"))
string.trim(str, ltrim, rtrim)#
Trim the string, remove the head and tail of the space
Parameters
Incoming Value Type |
Explanation |
---|---|
string |
String to be processed |
bool |
Cleanup prefix, default is true |
bool |
Cleanup suffix, defaults true |
Return Value
return value type |
explanation |
---|---|
string |
String after cleaning |
Examples
local str = "\r\nabc\r\n"
log.info("str", string.trim(str)) -- Print "abc"
log.info("str", str:trim()) -- Print "abc"
log.info("str", #string.trim(str, false, true)) -- Only the suffix is clipped, so the length is 5