Programmation Dart - Méthode de sous-chaîne

Renvoie la sous-chaîne de cette chaîne qui s'étend de startIndex, inclus, à endIndex, exclusif.

Syntaxe

substring(int startIndex, [ int endIndex ])

Paramètres

  • startIndex - l'index à partir duquel commencer l'extraction (inclus).

  • endIndex - l'index pour arrêter l'extraction (exclusif).

Note - Les index sont basés sur zéro, c'est-à-dire que le premier caractère aura l'index 0 et ainsi de suite.

Type de retour

Renvoie une chaîne.

Exemple

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 
}

Il produira ce qui suit output -.

New String: World 
New String: llo