English
String
About 596 wordsAbout 2 min
2026-01-09
String
String - A sequence of characters enclosed in double quotes ("") that can contain any characters (Chinese, English, symbols, etc.)
Summary
- Define a String:
String string = ""
Example:
String string = "Zhang San"
```text
- String methods:
`string.contains(<String str>)`: Checks if the string contains a specific sequence or character
Return type: Boolean
Example:
```text
"fx is great".contains("fx") // Returns: true
```text
`string.startsWith(<String str>)`: Checks if the string starts with the specified prefix
Return type: Boolean
Example:
```text
"fx is great".startsWith("fx") // Returns: true
```text
`string.endsWith(<String str>)`: Checks if the string ends with the specified suffix
Return type: Boolean
Example:
```text
"fx is great".endsWith("fx") // Returns: false
```text
`string.concat(<String str>)`: Concatenates the specified string to the end of this string
Return type: String
Example:
```text
"fx is great".concat("fx") // Returns: fx is greatfx
```text
`string.isEmpty()`: Checks if the string is empty
Return type: Boolean
Example:
```text
"fx ".isEmpty() // Returns: false
```text
`string.trim()`: Returns a copy of the string with leading and trailing whitespace omitted
Return type: String
Example:
```text
" Welcome to fxiaoke Creator ".trim() // Returns: Welcome to fxiaoke Creator
```text
`string.replace(<String searchString>,<String replacement>)`: Replaces all occurrences of searchString with replacement
Return type: String
Example:
```text
"Red,Green,Green".replace("Green","Blue") // Returns: Red,Blue,Blue
```text
`string.replaceAll(<String regex>,<String replacement>)`: Replaces all substrings matching the regex with replacement
Return type: String
Example:
```text
"Red,Green,Green".replaceAll("Green","Blue") // Returns: Red,Blue,Blue
```text
`string.substring(<Integer startIndex>,<Integer endIndex>)`: Returns a new substring from startIndex (inclusive) to endIndex (exclusive)
Return type: String
Example:
```text
"www.fxiaoke.com".substring(4,11) // Returns: fxiaoke
```text
Note: Index starts at 0, so position 4 is 'f'. The result includes startIndex but excludes endIndex.
`string.split(<String regex>)` or `string.split(<String regex>,<Integer limit>)`: Splits the string around matches of the given regex
Return type: String[]
Example:
```text
"www-fxiaoke-com".split("-") // Returns: ["www","fxiaoke","com"]
"www-fxiaoke-com".split("-","2") // Returns: ["www","fxiaoke-com"]
```text
Note: The limit parameter controls the maximum number of splits.
`string.length()`: Returns the length of the string
Return type: BigDecimal
Example:
```text
"www.fxiaoke.com".length() // Returns: 15
```text
`string.indexOf(<String subString>)`: Returns the index of the first occurrence of the substring (starting from 0 by default)
or `string.indexOf(<String subString>,<BigDecimal fromIndex>)`: Returns the index of the first occurrence after fromIndex
Return type: BigDecimal
Example:
```text
"www.fxiaoke.com".indexOf("o") // Returns: 8
"www.fxiaoke.com".indexOf("o",9) // Returns: 13
```text
`string.lastIndexOf(<String subString>)`: Returns the index of the last occurrence of the substring
or `string.lastIndexOf(<String subString>,<BigDecimal fromIndex>)`: Returns the index of the last occurrence before fromIndex
Return type: BigDecimal
Example:
```text
"www.fxiaoke.com".lastIndexOf("o") // Returns: 13
"www.fxiaoke.com".lastIndexOf("o",9) // Returns: 8
```text
`string.toUpperCase()`: Converts all characters to uppercase
Return type: String
Example:
```text
"abc".toUpperCase() // Returns: ABC
```text
`string.toLowerCase()`: Converts all characters to lowercase
Return type: String
Example:
```text
"ABC".toLowerCase() // Returns: abc
```text
## Changelog
| Version | Date | Changes | Author |
| --- | --- | --- | --- |
| v1.0 | 2026-05-20 | Initial version | |
## Background
This document provides detailed information about the String API functionality and usage, helping developers integrate relevant capabilities.
## Applicable Scenarios
Specific applicable scenarios are determined by actual business needs. Developers can select the appropriate API for integration as required.
## Prerequisites
- Access to Fxiaoke Open Platform
- Application authorization and configuration completed
- Basic knowledge of relevant business domain
## Steps
Please refer to the detailed instructions for each API.
> **Compatibility:** This version currently has no deprecated or compatibility notes.