目录

substring()

返回此字符串的子字符串,该字符串从startIndex(包括)延伸到endIndex,exclusive。

语法 (Syntax)

substring(int startIndex, [ int endIndex ])

参数 (Parameters)

  • startIndex - 从(包含)开始提取的索引。

  • endIndex - 停止提取的索引(不包括)。

Note - 索引基于零,即第一个字符的索引为0,依此类推。

返回值 (Return Type)

返回一个字符串。

例子 (Example)

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 
} 

它将产生以下output - 。

New String: World 
New String: llo 
↑回到顶部↑
WIKI教程 @2018