String String operations

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

APIDescription
String.lenReturns the string length. ASCII strings are measured in bytes; non-ASCII strings are measured in Unicode characters.
String.trimRemove leading and trailing blank characters from the string and return a new string.
String.trim_startRemove blank characters at the beginning of the string and return a new string.
String.trim_endRemove blank characters from the end of the string and return a new string.
String.char_atRead the character at the specified character position.
String.char_code_atRead the Unicode code point at the specified character position.
String.parse_jsonParse JSON string into BT value.
String.parse_radix_intParse integer text according to the specified base.
String.parse_radix_strParses whitespace-delimited byte text into a UTF-8 string according to the specified base.
String.concatConcatenate the current string and all parameters in sequence into a new string.
String.ends_withDetermine whether the string ends with the specified suffix.
String.containsDetermine whether the string contains the specified fragment.
String.index_ofReturns the position where the specified fragment first appears.
String.last_index_ofReturns the position of the last occurrence of the specified fragment.
String.repeatRepeat the current string the number of times.
String.replaceReplace 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_allReplace all matching content in the string.
String.searchFind the first matching position of a string or regular expression in the current string.
String.matchReturns string or regular expression matching results.
String.sliceIntercept the string according to the starting and ending positions.
String.splitSplit a string by delimiter.
String.starts_withDetermine whether the string starts with the specified prefix.
String.substrIntercept the string by length starting from the specified position.
String.to_lowercaseConvert a string to lowercase.
String.to_uppercaseConvert a string to uppercase.
String.to_numberConvert a string into a numeric value according to BT relaxed number rules.
String.to_stringReturns the current string itself.
String.pad_startPad the string at the beginning to the target length.
String.pad_endPad the string at the end to the target length.

Examples

Notes

  • String methods return new values and do not modify the original string.
- HTML escaping, escaping and tag stripping have been migrated to html library .
  • The parameters of char_at and char_code_at are read according to Unicode character subscripts.
- Return positions for index_of, last_index_of, search are calculated as UTF-8 byte offsets.