startsWithCharacters method

bool startsWithCharacters(
  1. String characters, {
  2. bool matchCase = false,
})

Checks if the String starts with the given characters, with an optional case sensitivity.

Returns true if the string starts with the specified characters, otherwise returns false. The comparison can be case-sensitive or case-insensitive, depending on the matchCase parameter.

Example:

String? text = "Hello World";
print(text.startsWithCharacters("Hello")); // true
print(text.startsWithCharacters("hello", matchCase: true)); // false
print(text.startsWithCharacters("hello", matchCase: false)); // true

Implementation

bool startsWithCharacters(String characters, {bool matchCase = false}) {
  if (characters.isEmpty || isEmptyOrNull) {
    return false;
  }
  if (matchCase) {
    return this!.startsWith(characters);
  }
  return this!.toLowerCase().startsWith(characters.toLowerCase());
}