startsWith abstract method
Whether this string starts with a match ofpattern.
const string = 'Dart is open source';print(string.startsWith('Dar')); // trueprint(string.startsWith(RegExp(r'[A-Z][a-z]'))); // trueIfindex is provided, this method checks if the substring startingat that index starts with a match ofpattern:
const string = 'Dart';print(string.startsWith('art', 0)); // falseprint(string.startsWith('art', 1)); // trueprint(string.startsWith(RegExp(r'\w{3}'), 2)); // falseindex must not be negative or greater thanlength.
ARegExp containing '^' does not match if theindex is greater thanzero and the regexp is not multi-line.The pattern works on the string as a whole, and does not extracta substring starting atindex first:
const string = 'Dart';print(string.startsWith(RegExp(r'^art'), 1)); // falseprint(string.startsWith(RegExp(r'art'), 1)); // trueImplementation
bool startsWith(Pattern pattern, [int index = 0]);