- Dart Programming - HTML DOM
- Dart Programming - Unit Testing
- Dart Programming - Concurrency
- Dart Programming - Async
- Dart Programming - Libraries
- Dart Programming - Typedef
- Dart Programming - Debugging
- Dart Programming - Exceptions
- Dart Programming - Packages
- Dart Programming - Generics
- Dart Programming - Collection
- Dart Programming - Object
- Dart Programming - Classes
- Dart Programming - Interfaces
- Dart Programming - Functions
- Dart Programming - Enumeration
- Dart Programming - Runes
- Dart Programming - Symbol
- Dart Programming - Map
- Dart Programming - Lists
- Dart Programming - Lists
- Dart Programming - Boolean
- Dart Programming - String
- Dart Programming - Numbers
- Dart Programming - Decision Making
- Dart Programming - Loops
- Dart Programming - Operators
- Dart Programming - Variables
- Dart Programming - Data Types
- Dart Programming - Syntax
- Dart Programming - Environment
- Dart Programming - Overview
- Dart Programming - Home
Dart Programming Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Dart Programming - Runes
Strings are a sequence of characters. Dart represents strings as a sequence of Unicode UTF-16 code units. Unicode is a format that defines a unique numeric value for each letter, digit, and symbol.
Since a Dart string is a sequence of UTF-16 code units, 32-bit Unicode values within a string are represented using a special syntax. A rune is an integer representing a Unicode code point.
The String class in the dart:core pbrary provides mechanisms to access runes. String code units / runes can be accessed in three ways −
Using String.codeUnitAt() function
Using String.codeUnits property
Using String.runes property
String.codeUnitAt() Function
Code units in a string can be accessed through their indexes. Returns the 16-bit UTF-16 code unit at the given index.
Syntax
String.codeUnitAt(int index);
Example
import dart:core ; void main(){ f1(); } f1() { String x = Runes ; print(x.codeUnitAt(0)); }
It will produce the following output −
82
String.codeUnits Property
This property returns an unmodifiable pst of the UTF-16 code units of the specified string.
Syntax
String. codeUnits;
Example
import dart:core ; void main(){ f1(); } f1() { String x = Runes ; print(x.codeUnits); }
It will produce the following output −
[82, 117, 110, 101, 115]
String.runes Property
This property returns an iterable of Unicode code-points of this string.Runes extends iterable.
Syntax
String.runes
Example
void main(){ "A string".runes.forEach((int rune) { var character=new String.fromCharCode(rune); print(character); }); }
It will produce the following output −
A s t r i n g
Unicode code points are usually expressed as uXXXX, where XXXX is a 4-digit hexadecimal value. To specify more or less than 4 hex digits, place the value in curly brackets. One can use the constructor of the Runes class in the dart:core pbrary for the same.
Example
main() { Runes input = new Runes( u{1f605} ); print(new String.fromCharCodes(input)); }
It will produce the following output −
Advertisements