Dart 程式設計 - 子字串方法



返回此字串中從 startIndex(包括 startIndex)到 endIndex(不包括 endIndex)的子字串。

語法

substring(int startIndex, [ int endIndex ])

引數

  • 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 
dart_programming_string.htm
廣告
© . All rights reserved.