In Dart, strings are represented as sequences of Unicode UTF-16 code units. The Unicode format maps a unique numeric character to each letter, digit, and symbol. The code below shows Unicode equivalents of some characters.
import 'dart:convert';void main() {//Unicode equivalent of uppercase Mvar uppercaseM = '\u{004d}';print(uppercaseM);//Unicode equivalent of the digit 7var seven = '\u{0037}';print(seven);//Unicode equivalent of the the dollar signvar dollarSign = '\u{0024}';print(dollarSign);//Unicode equivalent of the thumbs-up emojivar thumbsUp = '\u{1f44d}';print(thumbsUp);}
A rune is an integer that represents a Unicode code point. The dart:core library allows runes to be accessed from Dart strings. There are three main methods used for this purpose:
String.codeUnitAt(int index)
import 'dart:convert';void main() {String string = 'Educative';//UTF-16 code unit for 'd' at second index of stringprint(string.codeUnitAt(1));//UTF-16 code unit for 't' at sixth index of stringprint(string.codeUnitAt(5));}
String.codeUnits
import 'dart:convert';void main() {String string = 'Educative';//UTF-16 code unit list for the string aboveprint(string.codeUnits);}
String.runes
import 'dart:convert';void main() {String string = 'Educative';//Iterating over Unicode code-points of the string abovestring.runes.forEach((int rune) {var char=new String.fromCharCode(rune);print(char);});}
Free Resources