Search, Split, and Format
str_count
Calculates the number of occurrences of a character in a string.
- Format
str_count(value, sub, start, end)
- Parameter description
Parameter
Type
Mandatory
Description
value
Any (automatically converted to string)
Yes
Original string to be counted.
sub
Any (automatically converted to string)
Yes
Characters to be counted.
start
Number
No
Position where the search starts.
- 0 (default value): first character.
- –1: last character.
end
Number
No
Position where the search ends.
- 0: first character.
- –1 (default value): last character.
- Returned result
Returns the number of occurrences of a specified character.
- Function example
- Test data
{ "name": "lts is a log service" }
- Processing rule
e_set("str_count", str_count(v("name"), "l"))
- Processing result
name: lts is a log service str_count: 2
- Test data
str_find
Checks whether the original string contains the specified substring.
- Format
str_find(value, str, begin, end)
- Parameter description
Parameter
Type
Mandatory
Description
value
Any (automatically converted to string)
Yes
Original string to be searched.
str
Any (automatically converted to string)
Yes
Substring to be searched.
begin
Number
No
Start index. The default value is 0, indicating the first character. The value –1 indicates the last character.
end
Number
No
End index. The default value is the length of the string. The value 0 indicates the first character, and the value –1 indicates the last character.
- Returned result
Returns the position of the first occurrence of the specified substring within the original string.
- Function example
- Test data
{ "name": "lts is a log service" }
- Processing rule
e_set("str_find",str_find(v("name"), "l"))
- Processing result
name: lts is a log service str_find: 0
- Test data
str_rfind
Checks whether the original string contains the specified substring.
- Format
str_rfind(value, substr, beg, end)
- Parameter description
Parameter
Type
Mandatory
Description
value
Any (automatically converted to string)
Yes
Original string to be searched.
substr
Any (automatically converted to string)
Yes
Character to be searched.
beg
Number
No
Start position of the search. The default value is 0.
end
Number
No
End position of the search. The default value is the length of the string.
- Returned result
Returns the position of the last appearance of a character or string.
- Function example
- Test data
{ "name": "lts is a log service" }
- Processing rule
e_set("str_rfind", str_rfind(v("name"), "i"))
- Processing result
name: lts is a log service str_rfind: 17
- Test data
str_endswith
Checks whether a string ends with a specified suffix.
- Format
str_endswith(value, suffix, start, end)
- Parameter description
Parameter
Type
Mandatory
Description
value
Any (automatically converted to string)
Yes
Original character string to be checked.
suffix
Any (automatically converted to string)
Yes
Suffix rule. This parameter can be a string or an element.
start
Number
No
Start position of the string to be checked. The value 0 indicates the first character, and the value –1 indicates the last character.
end
Number
No
End position of the string to be checked. The value 0 indicates the first character, and the value –1 indicates the last character.
- Returned result
Returns true if the string ends with the specified suffix, and returns false otherwise.
- Function example
- Test data
{ "name": "lts is a log service" }
- Processing rule
e_set("str_endswith",str_endswith(v("name"), "service"))
- Processing result
name: lts is a log service str_endswith: true
- Test data
str_startswith
Checks whether a string starts with specified characters.
- Format
str_startswith(value, prefix, start, end)
- Parameter description
Parameter
Type
Mandatory
Description
value
Any (automatically converted to string)
Yes
Original character string to be checked.
prefix
Any (automatically converted to string)
Yes
Prefix rule. This parameter can be a string or an element.
start
Number
No
Start position of the string to be checked. The value 0 indicates the first character, and the value –1 indicates the last character.
end
Number
No
End position of the string to be checked. The value 0 indicates the first character, and the value –1 indicates the last character.
- Returned result
Returns true if the string starts with the specified prefix, and returns false otherwise.
- Function example
- Test data
{ "name": "lts is a log service" }
- Processing rule
e_set("str_startswith",str_startswith(v("name"), "lts"))
- Processing result
name: lts is a log service str_startswith: true
- Test data
str_split
Splits a string by specifying delimiters.
- Format
str_split(value, sep=None, maxsplit=-1)
- Parameter description
Parameter
Type
Mandatory
Description
value
Any (automatically converted to string)
Yes
Original string to be split.
sep
Number
No
Separator. None indicates a space.
maxsplit
Number
No
Maximum number of splits. –1 indicates no limit.
- Returned result
Processed string.
- Function example
- Test data
{ "content": "lts,a,log,service" }
- Processing rule
e_set("str_split", str_split(v("content"), ","))
- Processing result
content: lts,a,log,service str_split: ["lts","a","log","service"]
- Test data
str_splitlines
Splits a string by specifying newline characters.
- Format
str_splitlines(value, keepends)
- Parameter description
Parameter
Type
Mandatory
Description
value
Any (automatically converted to string)
Yes
Original string to be split.
keepends
Boolean
No
Whether to remove line breaks (\r, \r\n, and \n) from the output. The default value is false, indicating that line breaks are not contained. If the value is true, line breaks are retained.
- Returned result
Processed list.
- Function example
- Test data
{ "value": "lts\nis\ra\r\n" }
- Processing rule
e_set("str_splitlines", str_splitlines(v("value"), false))
- Processing result
value: lts\nis\ra\r\n str_splitlines: ['lts','is','a']
- Test data
str_partition
Splits a string into three parts from left to right based on the specified delimiters.
- Format
str_partition(value, substr)
- Parameter description
Parameter
Type
Mandatory
Description
value
Any (automatically converted to string)
Yes
String to be split.
substr
Any (automatically converted to string)
No
Specified separator.
- Returned result
List after splitting.
- Function example
- Test data
{ "address": "big.middle.small" }
- Processing rule
e_set("str_partition", str_partition(v("address"), "."))
- Processing result
address: big.middle.small str_partition: ["big",".","middle.small"]
- Test data
str_rpartition
Splits a string into three parts from right to left based on the specified delimiters.
- Format
str_rpartition(value, substr)
- Parameter description
Parameter
Type
Mandatory
Description
value
Any (automatically converted to string)
Yes
Original string to be split.
substr
Any (automatically converted to string)
No
Specified separator.
- Returned result
List after splitting.
- Function example
- Test data
{ "address": "big.middle.small" }
- Processing rule
e_set("str_partition", str_rpartition(v("address"), "."))
- Processing result
address: big.middle.small str_partition: ["big.middle",".","small"]
- Test data
str_center
Expands a string to a specified length with specified characters.
- Format
str_center(value, width, fillchar)
- Parameter description
Parameter
Type
Mandatory
Description
value
Any (automatically converted to string)
Yes
Original string to be modified.
width
Number
Yes
Total length of the string after padding.
fillchar
Any (automatically converted to string)
No
Padding character. The default value is a space.
- Returned result
Processed string.
- Function example
- Test data
{ "value": "lts is a log service" }
- Processing rule
e_set("str_center", str_center(v("value"), 40, "*"))
- Processing result
center: lts is a log service str_center: **********lts is a log service**********
- Test data
str_ljust
Expands a string to a specified length with specified characters starting from the end of the string.
- Format
str_ljust(value, width, fillchar)
- Parameter description
Parameter
Type
Mandatory
Description
value
Any (automatically converted to string)
Yes
Original string to be modified.
width
Number
Yes
Total length of the string after padding.
fillchar
Any (automatically converted to string)
No
Padding character. The default value is a space.
- Returned result
Processed string.
- Function example
- Test data
{ "value": "lts is a log service" }
- Processing rule
e_set("str_ljust", str_ljust(v("value"), 30, "*"))
- Processing result
value: lts is a log service str_ljust: lts is a log service**********
- Test data
str_rjust
Expands a string to a specified length with specified characters starting from the beginning of the string.
- Format
str_rjust(value, width, fillchar)
- Parameter description
Parameter
Type
Mandatory
Description
value
Any (automatically converted to string)
Yes
Original string to be modified.
width
Number
Yes
Total length of the string after padding.
fillchar
Any (automatically converted to string)
No
Padding character. The default value is a space.
- Returned result
Processed string.
- Function example
- Test data
{ "value": "lts is a log service" }
- Processing rule
e_set("str_rjust", str_rjust(v("value"), 30, "*"))
- Processing result
value: lts is a log service str_ljust: **********lts is a log service
- Test data
str_zfill
Expands a string to a specified length with the character 0 starting from the beginning of the string.
- Format
str_zfill(value, width)
- Parameter description
Parameter
Type
Mandatory
Description
value
Any (automatically converted to string)
Yes
Original string to be modified.
width
Number
Yes
Total length of the string after padding.
- Returned result
Processed string.
- Function example
- Test data
{ "value": "this is lts" }
- Processing rule
e_set("str_zfill", str_zfill(v("value"), 20))
- Processing result
value: this is lts str_zfill: 000000000this is lts
- Test data
str_expandtabs
Converts \t in a string to a space.
- Format
str_expandtabs(value, tabsize)
- Parameter description
Parameter
Type
Mandatory
Description
value
Any (automatically converted to string)
Yes
Original string to be modified.
tabsize
Number
No
Number of spaces after conversion.
- Returned result
Processed string.
- Function example
- Example 1: Converts the \t character in the key to a space.
- Test data
{ "key": "this is\tlts" }
- Processing rule
e_set("str_expandtabs", str_expandtabs(v("key")))
- Processing result
key: this is\tlts str_expandtabs: this is lts
- Test data
- Example 2: Converts the \t character in the key to a space and pads the specified number of spaces.
- Test data
{ "key": "this is\tlts" }
- Processing rule
e_set("str_expandtabs", str_expandtabs(v("key"), 5))
- Processing result
key: this is\tlts str_expandtabs: this is lts
- Test data
- Example 1: Converts the \t character in the key to a space.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot