Dart String.substring()方法返回此字串的子字串,該字串從startIndex(包括)延伸到endIndex(不包括)。
語法
String.substring()
返回值
startIndex- 開始提取的索引(包含)。endIndex- 提取的結束索引(不包括)。
注 - 索引基於
0,即第一個字元的索引為0,依此類推。
示例
void main() {
String str1 = "Hello World";
print("New String: ${str1.substring(6)}");
// from index 6 to the last index
print("New String: ${str1.substring(2,6)}");
// from index 2 to the 6th index
}
執行上面示例代碼,得到以下結果 -
New String: World
New String: llo
