tencent cloud

Cloud Log Service

String Processing Function

Download
Mode fokus
Ukuran font
Terakhir diperbarui: 2026-06-04 18:19:13

Introduction

String processing function, supporting string length calculation, case conversion, string concatenation, replacement, elimination, search for character location, prefix and suffix matching, etc.

str_exist Function

Function Definition

Find a substring within the specified range of values and return True or False.

Syntax Description

str_exist(string_value, substring_value, ignore_upper=False)

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
String value
Value of the string
String
Yes
-
-
Substring value
Value of the substring
String
Yes
-
-
ignore_upper
Is It Case sensitivity
Bool
No
False
-

Example

Raw logs:
{"data": "cls nihao"}
Processing rules:
fields_set("result", str_exist(v(data), "nihao"))
Processing result:
{"result":"true","data":"cls nihao"}

str_existV2 Function

Function Definition

Determine whether multiple substrings exist. It returns True if at least one substring is found, and False if none are found.

Syntax Description

str_existV2(string_value, substring_value1, substring_value2, ..., ignore_upper=False)

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
String value
Value of the string
String
Yes
-
-
Substring value 1
Value of the substring
String
Yes
-
-
Substring value 2
Value of the substring
String
Yes
-
-
ignore_upper
Is It Case sensitivity
Bool
No
False
-

Example

Raw logs:
{"data": "cls nihao"}
Processing rules:
fields_set("result", str_existV2(v(data), "nihao","hello"))
Processing result:
{"result":"true","data":"cls nihao"}

str_count Function

Function Definition

Find a substring within the specified range of values and return the number of occurrences of the substring.

Syntax Description

str_count(value, sub="", start=0, end=-1)

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
data
Value of string type
string
Yes
-
-
sub
Substring to be searched for
string
Yes
-
-
start
Start Position of Search
number
No
The default is 0.
-
end
End Position of Search
number
No
The default is -1.
-

Example

Raw logs:
{"data": "warn,error,error"}
Processing rules:
fields_set("result", str_count(v("data"), sub="err"))
Processing result:
{"result":"2","data":"warn,error,error"}

str_len Function

Function Definition

Return the string length.

Syntax Description

str_len (value)

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
data
Value of string type
string
Yes
-
-

Example

Raw logs:
{"data": "warn,error,error"}
Processing rules:
fields_set("result", str_len(v("data")))
Processing result:
{"result":"16","data":"warn,error,error"}

str_uppercase Function

Function Definition

Return an uppercase string.

Syntax Description

str_uppercase (value)

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
data
Value of string type
string
Yes
-
-

Example

Raw logs:
{"data": "warn,error,error"}
Processing rules:
fields_set("result", str_uppercase(v("data")))
Processing result:
{"result":"WARN,ERROR,ERROR","data":"warn,error,error"}

str_lowercase Function

Function Definition

Return a lowercase string.

Syntax Description

str_lowercase (value)

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
data
Value of string type
string
Yes
-
-

Example

Raw logs:
{"data": "WARN,ERROR,ERROR"}
Processing rules:
fields_set("result", str_lowercase(v("data")))
Processing result:
{"result":"warn,error,error","data":"WARN,ERROR,ERROR"}

str_join Function

Function Definition

Use concatenated strings to concatenate multiple values.

Syntax Description

str_join (concatenation string 1, value 1, value 2, ...)

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
join
Value of string type
string
Yes
-
-
Value Parameter, List of Variable Parameters
Value of string type
string
Yes
-
-

Example

Raw logs:
{"data": "WARN,ERROR,ERROR"}
Processing rules:
fields_set("result", str_join(",", v("data"), "INFO"))
Processing result:
{"result":"WARN,ERROR,ERROR,INFO","data":"WARN,ERROR,ERROR"}

str_replace Function

Function Definition

Replace string, and return the replacement result string.

Syntax Description

str_replace (value, old="", new="", count=0)

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
data
Value of string type
string
Yes
-
-
old
String to be Replaced
string
Yes
-
-
new
Target String to be Replaced
string
Yes
-
-
count
Maximum replacement times, all replaced by default
number
No
The default is 0.
-

Example

Replace "WARN" in the value of field data with "ERROR".
Raw logs:
{"data": "WARN,ERROR,ERROR"}
Processing rule: Save the replacement result to a new field named "result".
fields_set("result", str_replace( v("data"), old="WARN", new="ERROR"))
Processing result:
{"result":"ERROR,ERROR,ERROR","data":"WARN,ERROR,ERROR"}

str_format Function

Function Definition

Format the string and return the formatted result.

Syntax Description

str_format (formatting string, value 1, value 2, ...)

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
format
The target format uses placeholders {}, for example: "The disk contains {0} files.". The number inside the placeholder {} corresponds to the index of the subsequent parameter value, starting from 0. For specific usage, refer to the MessageFormat.format function.
string
Yes
-
-
Value Parameter, List of Variable Parameters
Value of string type
string
Yes
-
-

Example

Raw logs:
{"status": 200, "message":"OK"}
Processing rules:
fields_set("result", str_format("status:{0}, message:{1}", v("status"), v("message")))
Processing result:
{"result":"status:200, message:OK","message":"OK","status":"200"}

str_strip Function

Function Definition

Remove specified characters from the beginning and end of a string.

Syntax Description

str_strip (value, chars="\\t\\r\\n")

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
data
Value of string type
string
Yes
-
-
chars
The string to be removed
string
No
\\t\\r\\n
-

Example

Example 1
Raw logs:
{"data": " abc "}
Processing rules:
fields_set("result", str_strip(v("data"), chars=" "))
Processing result:
{"result":"abc","data":" abc "}
Example 2
Raw logs:
{"data": " **abc** "}
Processing rules:
fields_set("result", str_strip(v("data"), chars=" *"))
Processing result:
{"result":"abc","data":" **abc** "}

str_lstrip Function

Function Definition

Remove specified characters from the beginning of a string.

Syntax Description

str_strip (value, chars="\\t\\r\\n")

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
data
Value of string type
string
Yes
-
-
chars
The string to be removed
string
No
\\t\\r\\n
-

Example

Raw logs:
{"data": " abc "}
Processing rules:
fields_set("result", str_lstrip(v("data"), chars=" "))
Processing result:
{"result":"abc ","data":" abc "}

str_rstrip Function

Function Definition

Remove specified characters from the end of a string.

Syntax Description

str_strip (value, chars="\\t\\r\\n")

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
data
Value of string type
string
Yes
-
-
chars
The string to be removed
string
No
\\t\\r\\n
-

Example

Raw logs:
{"data": " abc "}
Processing rules:
fields_set("result", str_rstrip(v("data"), chars=" "))
Processing result:
{"result":" abc","data":" abc "}

str_find Function

Function Definition

Find a substring in the value and returns where it appears.

Syntax Description

str_find (value, sub="", start=0, end=-1)

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
data
Value of string type
string
Yes
-
-
sub
Substrings to be Searched
string
Yes
-
-
start
Start Position of Search
number
No
The default is 0.
-
end
End Position of Search
number
No
The default is -1.
-

Example

Raw logs:
{"data": "warn,error,error"}
Processing rules:
fields_set("result", str_find(v("data"), sub="err"))
Processing result:
{"result":"5","data":"warn,error,error"}

str_start_with Function

Function Definition

Determine whether the string begins with a specified prefix.

Syntax Description

str_start_with (value, sub="", start=0, end=-1)

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
data
Value of string type
string
Yes
-
-
sub
Prefix string
string
Yes
-
-
start
Start Position of Search
number
No
The default is 0.
-
end
End Position of Search
number
No
The default is -1.
-

Example

Example 1
Raw logs:
{"data": "something"}
Processing rules:
fields_set("result", str_start_with(v("data"), sub="some"))
Processing result:
{"result":"true","data":"something"}
Example 2
Raw logs:
{"data": "something"}
Processing rules:
fields_set("result", str_start_with(v("data"), sub="*"))
Processing result:
{"result":"false","data":"something"}

str_end_with Function

Function Definition

Determine whether a string ends with a specified suffix.

Syntax Description

str_end_with (value, sub="", start=0, end=-1)

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
data
Value of string type
string
Yes
-
-
sub
Suffix string
string
Yes
-
-
start
Start Position of Search
number
No
The default is 0.
-
end
End Position of Search
number
No
The default is -1.
-

Example

Raw logs:
{"data": "endwith something"}
Processing rules:
fields_set("result", str_end_with(v("data"), sub="ing"))
Processing result:
{"result":"true","data":"endwith something"}


Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan