startsWith method Null safety

bool startsWith (
  1. Pattern pattern,
  2. [int index = 0]
)

Whether this string starts with a match of pattern.

var string = 'Dart';
string.startsWith('D');                       // true
string.startsWith(RegExp(r'[A-Z][a-z]')); // true

If index is provided, this method checks if the substring starting at that index starts with a match of pattern:

string.startsWith('art', 1);                  // true
string.startsWith(RegExp(r'\w{3}'));      // true

index must not be negative or greater than length.

A RegExp containing '^' does not match if the index is greater than zero and the regexp is not multi-line. The pattern works on the string as a whole, and does not extract a substring starting at index first:

string.startsWith(RegExp(r'^art'), 1);    // false
string.startsWith(RegExp(r'art'), 1);     // true

Implementation

bool startsWith(Pattern pattern, [int index = 0]);