api.flutter.dev Open in urlscan Pro
2620:0:890::100  Public Scan

URL: https://api.flutter.dev/flutter/dart-core/String/split.html
Submission: On October 13 via manual from YE — Scanned from DE

Form analysis 2 forms found in the DOM

<form class="search navbar-right" role="search">
  <div class="tt-wrapper"><input type="text" autocomplete="off" readonly="true" spellcheck="false" tabindex="-1" class="typeahead tt-hint"><input type="text" id="search-box" autocomplete="off" class="form-control typeahead tt-input"
      placeholder="Search API Docs" spellcheck="false">
    <div role="listbox" aria-expanded="false" class="tt-menu" style="display: none;">
      <div class="tt-elements"></div>
    </div>
  </div>
</form>

<form class="search-sidebar" role="search">
  <div class="tt-wrapper"><input type="text" autocomplete="off" readonly="true" spellcheck="false" tabindex="-1" class="typeahead tt-hint"><input type="text" id="search-sidebar" autocomplete="off" class="form-control typeahead tt-input"
      placeholder="Search API Docs" spellcheck="false">
    <div role="listbox" aria-expanded="false" class="tt-menu" style="display: none;">
      <div class="tt-elements"></div>
    </div>
  </div>
</form>

Text Content

 
 1. Flutter
 2. dart:core
 3. String
 4. split abstract method

split



SPLIT METHOD NULL SAFETY

List<String> split(
 1. Pattern pattern

)

Splits the string at matches of pattern and returns a list of substrings.

Finds all the matches of pattern in this string, as by using Pattern.allMatches,
and returns the list of the substrings between the matches, before the first
match, and after the last match.

const string = 'Hello world!';
final splitted = string.split(' ');
print(splitted); // [Hello, world!];


If the pattern doesn't match this string at all, the result is always a list
containing only the original string.

If the pattern is a String, then it's always the case that:

string.split(pattern).join(pattern) == string


If the first match is an empty match at the start of the string, the empty
substring before it is not included in the result. If the last match is an empty
match at the end of the string, the empty substring after it is not included in
the result. If a match is empty, and it immediately follows a previous match (it
starts at the position where the previous match ended), then the empty substring
between the two matches is not included in the result.

const string = 'abba';
final re = RegExp(r'b*');
// re.allMatches(string) will find four matches:
// * empty match before first "a".
// * match of "bb"
// * empty match after "bb", before second "a"
// * empty match after second "a".
print(string.split(re)); // [a, a]


A non-empty match at the start or end of the string, or after another match, is
not treated specially, and will introduce empty substrings in the result:

const string = 'abbaa';
final splitted = string.split('a'); // ['', 'bb', '', '']


If this string is the empty string, the result is an empty list if pattern
matches the empty string, since the empty string before and after the
first-and-last empty match are not included. (It is still a list containing the
original empty string [""] if the pattern doesn't match).

const string = '';
print(string.split('')); // []
print(string.split('a')); // []


Splitting with an empty pattern splits the string into single-code unit strings.

const string = 'Pub';
print(string.split('')); // [P, u, b]

// Same as:
var codeUnitStrings = [
  for (final unit in string.codeUnits) String.fromCharCode(unit)
];
print(codeUnitStrings); // [P, u, b]


Splitting happens at UTF-16 code unit boundaries, and not at rune (Unicode code
point) boundaries:

// String made up of two code units, but one rune.
const string = '\u{1D11E}';
final splitted = string.split('');
print(splitted); // ['\ud834', '\udd1e'] - 2 unpaired surrogate values


To get a list of strings containing the individual runes of a string, you should
not use split. You can instead get a string for each rune as follows:

const string = '\u{1F642}';
for (final rune in string.runes) {
  print(String.fromCharCode(rune));
}



IMPLEMENTATION

List<String> split(Pattern pattern);

 1. Flutter
 2. dart:core
 3. String
 4. split abstract method

STRING CLASS

 1.  Constructors
 2.  fromCharCode
 3.  fromCharCodes
 4.  fromEnvironment
 5.  Properties
 6.  codeUnits
 7.  hashCode
 8.  isEmpty
 9.  isNotEmpty
 10. length
 11. runes
 12. runtimeType
 13. Methods
 14. allMatches
 15. codeUnitAt
 16. compareTo
 17. contains
 18. endsWith
 19. indexOf
 20. lastIndexOf
 21. matchAsPrefix
 22. noSuchMethod
 23. padLeft
 24. padRight
 25. replaceAll
 26. replaceAllMapped
 27. replaceFirst
 28. replaceFirstMapped
 29. replaceRange
 30. split
 31. splitMapJoin
 32. startsWith
 33. substring
 34. toLowerCase
 35. toString
 36. toUpperCase
 37. trim
 38. trimLeft
 39. trimRight
 40. Operators
 41. operator *
 42. operator +
 43. operator ==
 44. operator []


Flutter 3.3.3 • 2022-09-28 12:35 • 18a827f393 • stable