splitFirst method
- string pattern
Splits the string using the specified pattern
and returns a list containing the first element and the remaining elements joined by the pattern
.
If the string cannot be split, it returns a list containing the original string.
Implementation
List<string> splitFirst(string pattern) {
var parts = split(pattern);
if (parts.length < 2) {
return [this];
}
var first = parts.removeAt(0);
return [first, parts.join(pattern)];
}