A string is the data type used to store a group of characters. Each character represents Unicode UTF-16 characters. Each Unicode character represents an int number for alphabets, numbers and special characters.

In Dart, Unicode is represented in runes class types as an integer number. The string class has different methods to access the Runes integer.

  • String.codeUnits
  • String.runes
  • String.codeUnitAt() method

String. runes property in dart

It returns iterable Unicode numbers of a given string Syntax

Runes get runes

Here is an example program

void main() {
  var str = "2022 \u00a9 Website";

  var unicodeValues = str.runes;
  print(unicodeValues.runtimeType); //Runes
  print(unicodeValues); //(50, 48, 50, 50, 32, 169, 32, 87, 101, 98, 115, 105, 116, 101)

}

Output:

Runes
(50, 48, 50, 50, 32, 169, 32, 87, 101, 98, 115, 105, 116, 101)

dart Runes codeUnits property

codeUnits return unmodified Unicode code units of a given string.

Syntax.

List<int> get codeUnits
void main() {
  var str = "2022 \u00a9 Website";
  print(str.codeUnits); 
}

output:

[50, 48, 50, 50, 32, 169, 32, 87, 101, 98, 115, 105, 116, 101]

dart Runes codeUnitAt method

codeUnitAt returns the Unicode value for a given index of a string.

int codeUnitAt(int index)

Here is an example

void main() {
  var str = "2022 \u00a9 Website";
  print(str); 

  var unicodeValue = str.codeUnitAt(6);

  print(unicodeValue); //32
}

Output:

2022 © Website
32