splitByCharacter method

List<String> splitByCharacter()

Converts String to an array of one character at a time.

Stringを1文字ずつの配列に変換します。

final text = "abcde";
final characters = ["a", "b", "c", "d", "e"];

Implementation

List<String> splitByCharacter() {
  if (isEmpty) {
    return <String>[];
  }
  if (length <= 1) {
    return [this];
  }
  final tmp = <String>[];
  for (int i = 0; i < length; i++) {
    tmp.add(substring(i, min(i + 1, length)));
  }
  return tmp;
}