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
