String String operations
String String operations
Function
String prototype function provides length reading, search matching, interception, replacement, filling, case conversion and type conversion capabilities.
API List
| API | Description |
|---|---|
| String.len | Returns the string length. ASCII strings are measured in bytes; non-ASCII strings are measured in Unicode characters. |
| String.trim | Remove leading and trailing blank characters from the string and return a new string. |
| String.trim_start | Remove blank characters at the beginning of the string and return a new string. |
| String.trim_end | Remove blank characters from the end of the string and return a new string. |
| String.char_at | Read the character at the specified character position. |
| String.char_code_at | Read the Unicode code point at the specified character position. |
| String.parse_json | Parse JSON string into BT value. |
| String.parse_radix_int | Parse integer text according to the specified base. |
| String.parse_radix_str | Parses whitespace-delimited byte text into a UTF-8 string according to the specified base. |
| String.concat | Concatenate the current string and all parameters in sequence into a new string. |
| String.ends_with | Determine whether the string ends with the specified suffix. |
| String.contains | Determine whether the string contains the specified fragment. |
| String.index_of | Returns the position where the specified fragment first appears. |
| String.last_index_of | Returns the position of the last occurrence of the specified fragment. |
| String.repeat | Repeat the current string the number of times. |
| String.replace | Replace matching content in a string. Only the first occurrence of a string pattern is replaced; all matches are replaced when the Regex parameter has the g flag. |
| String.replace_all | Replace all matching content in the string. |
| String.search | Find the first matching position of a string or regular expression in the current string. |
| String.match | Returns string or regular expression matching results. |
| String.slice | Intercept the string according to the starting and ending positions. |
| String.split | Split a string by delimiter. |
| String.starts_with | Determine whether the string starts with the specified prefix. |
| String.substr | Intercept the string by length starting from the specified position. |
| String.to_lowercase | Convert a string to lowercase. |
| String.to_uppercase | Convert a string to uppercase. |
| String.to_number | Convert a string into a numeric value according to BT relaxed number rules. |
| String.to_string | Returns the current string itself. |
| String.pad_start | Pad the string at the beginning to the target length. |
| String.pad_end | Pad the string at the end to the target length. |
Examples
text = ' BT Lang ' result = text.trim().to_uppercase() // Output: BT LANG print result
Notes
- String methods return new values and do not modify the original string.
- The parameters of
char_atandchar_code_atare read according to Unicode character subscripts.
index_of, last_index_of, search are calculated as UTF-8 byte offsets.