Dart Programming – Substring Method

  • Post author:
  • Post category:Dart
  • Post comments:2 Comments
Dart Programming Substring Method

In this guide, we will discuss the Substring Method in Dart Programming Language. Returns the substring of this string that extends from startIndex, inclusive, to endIndex, exclusive.

Syntax

substring(int startIndex, [ int endIndex ])

Parameters

  • startIndex − the index to start extracting from(inclusive).
  • endIndex − the index to stop extracting (exclusive).

Note − Indexes are zero based, i.e., the first character will have the index 0 and so on.

Return Type

Returns a string.

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 
} 

It will produce the following output −.

New String: World 
New String: llo 

Next Topic : Click Here

This Post Has 2 Comments

Leave a Reply