String
Overview
String related functions
upper
Converts all letters in a string to uppercase
String.upper(s);| Parameter | Type | Description |
|---|---|---|
| s | String | String to be converted |
Return Value
Type String Uppercase string, returns null if s is empty
Example
String.upper(1); //1
String.upper("Informat"); //INFORMAT
String.upper("abc"); //ABC
String.upper("aBC"); //ABC
String.upper(null); //nulllower
Converts all letters in a string to lowercase
String.lower(s);| Parameter | Type | Description |
|---|---|---|
| s | String | String to be converted |
Return Value
Type String Converted lowercase string, returns null if s is empty
Example
String.lower(1); //1
String.lower("Informat"); //informat
String.lower("ABC"); //abc
String.lower("aBC"); //abc
String.lower(null); //nullconcat
Combines strings s1 and s2 into a single string
String.concat(s1, s2);| Parameter | Type | Description |
|---|---|---|
| s1 | String | String to be concatenated |
| s2 | String | String to be concatenated |
Return Value
Type String Concatenated string
Example
String.concat("Informat", "Informat"); //Informat
String.concat("Informat", 1); //Informat1
String.concat("Informat", true); //Informattrue
String.concat("Informat", null); //Informat
String.concat(null, "Informat"); //Informat
String.concat(null, null); //nulllpad
Pads string s1 at the beginning with string s2 to make the string length reach len
String.lpad(s1, len, s2);| Parameter | Type | Description |
|---|---|---|
| s1 | String | String to be padded |
| s2 | String | Character to repeat |
| len | Integer | Total length |
Return Value
Type String Padded string
Example
String.lpad(1, 3, 0); //001
String.lpad("ABC", 6, 0); //000ABC
String.lpad("ABC", 6, "_"); //___ABC
String.lpad("ABC", 6, null); //ABC
String.lpad("ABC", 2, "0"); //ABC
String.lpad("ABC", null, 0); //ABC
String.lpad(null, 2, null); //null
String.lpad(null, null, null); //nullrpad
Pads string s1 at the end with string s2 to make the string length reach len
String.rpad(s1, len, s2);| Parameter | Type | Description |
|---|---|---|
| s1 | String | String to be padded |
| s2 | String | Character to repeat |
| len | Integer | Total length |
Return Value
Type String Padded string
Example
String.rpad(1, 3, 0); //100
String.rpad("ABC", 6, 0); //ABC000
String.rpad("ABC", 6, "_"); //ABC___
String.rpad("ABC", 6, null); //ABC
String.rpad("ABC", 2, "0"); //ABC
String.rpad("ABC", null, 0); //ABC
String.rpad(null, 2, null); //null
String.rpad(null, null, null); //nulltrim
Removes all whitespace characters from both sides of string s
String.trim(s);| Parameter | Type | Description |
|---|---|---|
| s | String | String to be processed |
Return Value
Type String String with whitespace characters removed
Example
String.trim(" abc "); //abc
String.trim(""); //
String.trim(null); //nullreplace
Replaces the first occurrence of string s1 in string s with string s2
String.replace(s, s1, s2);| Parameter | Type | Description |
|---|---|---|
| s | String | String to be processed |
| s1 | String | String to be replaced |
| s2 | String | Replacement string |
Return Value
Type String String with replaced content
Example
String.replace("abca", "a", "_"); //_bca
String.replace("abca", "a", ""); //bca
String.replace("abca", "a", null); //abca
String.replace("abca", null, "_"); //abca
String.replace(null, "a", "_"); //null
String.replace(null, null, "_"); //null
String.replace(null, null, null); //nullreplaceAll
Replaces all occurrences of string s1 in string s with string s2
String.replaceAll(s, s1, s2);| Parameter | Type | Description |
|---|---|---|
| s | String | String to be processed |
| s1 | String | String to be replaced |
| s2 | String | Replacement string |
Return Value
Type String String with replaced content
Example
String.replaceAll("abca", "a", "_"); //_bc_
String.replaceAll("abca", "a", ""); //bc
String.replaceAll("abca", "a", null); //abca
String.replaceAll("abca", null, "_"); //abca
String.replaceAll(null, "a", "_"); //null
String.replaceAll(null, null, "_"); //null
String.replaceAll(null, null, null); //nullsubstr
Extracts len characters from string s starting at index position start
String.substr(s, start, len);| Parameter | Type | Description |
|---|---|---|
| s | String | String to be processed |
| start | Integer | Starting position for extraction. Values start from 0. null defaults to 0 |
| len | Integer | Length to extract. null defaults to 0 |
Return Value
Type String Extracted string
Example
String.substr("abcd", 1, 2); //bc
String.substr("abcd", 1, 5); //bcd
String.substr("abcd", -1, 5); //abcd
String.substr("abcd", null, 5); //abcd
String.substr("abcd", 1, null); //
String.substr(null, null, 5); //nullsubstring
Extracts from string s starting at position start to ending position end
String.substring(s, start, end);| Parameter | Type | Description |
|---|---|---|
| s | String | String to be processed |
| start | Integer | Starting position for extraction. Values start from 0. null defaults to 0 |
| end | Integer | Ending position for extraction. Values start from 0. null defaults to 0 |
Return Value
Type String Extracted string
Example
String.substring("abcd", 0, 2); //ab
String.substring("abcd", 0, 5); //abcd
String.substring("abcd", -1, 5); //abcd
String.substring("abcd", 2, 3); //c
String.substring("abcd", null, 5); //abcd
String.substring("abcd", 1, null); //
String.substring(null, null, 5); //nullindexOf
Gets the position where character s2 first appears in string s
String.indexOf(s, s2);| Parameter | Type | Description |
|---|---|---|
| s | String | String to query |
| s2 | String | String s2 |
Return Value
Type Integer Position of first occurrence. Returns 0-indexed position if s contains s2, otherwise returns -1
Example
String.indexOf("abcd", "a"); //0
String.indexOf("abcad", "a"); //0
String.indexOf("abcd", "cd"); //2
String.indexOf("abcd", "g"); //-1
String.indexOf("abcd", null); //-1
String.indexOf(null, "a"); //-1
String.indexOf(null, null); //-1lastIndexOf
Gets the position where character s2 last appears in string s
String.lastIndexOf(s, s2);| Parameter | Type | Description |
|---|---|---|
| s | String | String to query |
| s2 | String | String s2 |
Return Value
Type Integer Position of last occurrence. Returns 0-indexed position if s contains s2, otherwise returns -1
Example
String.lastIndexOf("abcd", "a"); //0
String.lastIndexOf("abcad", "a"); //3
String.lastIndexOf("abcd", "cd"); //2
String.lastIndexOf("abcd", "g"); //-1
String.lastIndexOf("abcd", null); //-1
String.lastIndexOf(null, "a"); //-1
String.lastIndexOf(null, null); //-1contains
Determines whether string s contains character s2
String.contains(s, s2);| Parameter | Type | Description |
|---|---|---|
| s | String | String to query |
| s2 | String | String s2 |
Return Value
Type Boolean Whether it contains
Example
String.contains("abcd", "a"); //true
String.contains("abcad", "a"); //true
String.contains("abcd", "cd"); //true
String.contains("abcd", "g"); //false
String.contains("abcd", null); //false
String.contains(null, "a"); //false
String.contains(null, null); //falselength
Gets the length of string s
String.length(s);| Parameter | Type | Description |
|---|---|---|
| s | String | String to query |
Return Value
Type Integer String length
Example
String.length("abcd"); //4
String.length(null); //0startsWith
Determines whether string s starts with character s2
String.startsWith(s, s2);| Parameter | Type | Description |
|---|---|---|
| s | String | String to query |
| s2 | String | String s2 |
Return Value
Type Boolean
Example
String.startsWith("abcd", "a"); //true
String.startsWith("abcad", "bc"); //false
String.startsWith("abcad", "g"); //false
String.startsWith("abcad", ""); //true
String.startsWith("", ""); //true
String.startsWith(null, "a"); //false
String.startsWith(null, null); //falseendsWith
Determines whether string s ends with character s2
String.endsWith(s, s2);| Parameter | Type | Description |
|---|---|---|
| s | String | String to query |
| s2 | String | String s2 |
Return Value
Type Boolean
Example
String.endsWith("abcd", "a"); //false
String.endsWith("abcad", "bc"); //false
String.endsWith("abcad", "g"); //false
String.endsWith("abcad", ""); //true
String.endsWith("", ""); //true
String.endsWith(null, "a"); //false
String.endsWith(null, null); //falsematch
Uses regular expression regex to verify if input meets requirements
String.match(regex, input);| Parameter | Type | Description |
|---|---|---|
| regex | String | Regular expression content. Currently does not support shorthand regular expressions starting with \ like \w, \d |
| input | String | Content to match |
Return Value
Type Boolean
Example
String.match("^[a-z]+", "abcd"); //true
String.match("[^a-z]+", "abcd"); //false
String.match("[^a-z][a-zA-Z0-9]*", "123abcd"); //true
String.match("^[a-z]+", "abcd123"); //false
String.match("^[a-z]*", "abc123"); //false
String.match("^a[a-zA-Z0-9]*", "abc123"); //true
String.match("[a-zA-Z0-9]*[0-9]$", "abc123"); //true
String.match('^"[a-zA-Z0-9]*', '"abc123'); //true
String.match(null, "a"); //false
String.match(null, null); //falseisEmpty
Determines whether input string s is empty
String.isEmpty(s);| Parameter | Type | Description |
|---|---|---|
| s | String | Input content. The system automatically removes leading and trailing spaces from the string |
Return Value
Type Boolean
Example
String.isEmpty(" a "); //false
String.isEmpty(""); //true
String.isEmpty(" "); //true
String.isEmpty(null); //trueisNotEmpty
Determines whether input string s is not empty
String.isNotEmpty(s);| Parameter | Type | Description |
|---|---|---|
| s | String | Input content. The system automatically removes leading and trailing spaces from the string |
Return Value
Type Boolean
Example
String.isNotEmpty(" a "); //true
String.isNotEmpty(""); //false
String.isNotEmpty(" "); //false
String.isNotEmpty(null); //falsehtml2text
Converts HTML content in string s to text content. This process uses an XSS filter to filter content before output
String.html2text(s);| Parameter | Type | Description |
|---|---|---|
| s | String | Input content |
Return Value
Type String
Example
String.html2text("<div>demo data <strong>Informat</strong>,<a href='https://www.informat.cn'>click here</a></div>"); //demo data Informat,click here
String.html2text("<div>demo data <script>alert('Informat')</script>,<a href='https://www.informat.com'>click here</a></div>"); //demo data <script>alert('Informat')</script>,click here
String.html2text(""); //''
String.html2text(" "); //' '
String.html2text(null); //null
