×

Dart Runes and Graphemes

Runes and Graphemes data types in Dart

Runes and Graphemes

Runes are the special string of Unicode UTF-32 bits that represent the special syntax. Unicode defines a unique numeric value for each letter, digit, and symbol.

The Dart Runes are provided by the ‘ dart : core ’ library or ‘ package : characters ’.

Syntax of representing runes is :

\uXXXX, where XXXX is a 4-digit hexadecimal value

For example,

\u2665 corresponds to a heart character.

Program

import 'package:characters/characters.dart' ;


void main( )
{
  print( ' \u2665 ' ) ;
  print( ' \u{ 1f606 } ' ) ;
}

Output:

Dart Runes and Graphemes

The String code runes can be accessed using the following three methods :

  • Using String.codeUnitAt( ) function
  • Using String.codeUnits property
  • Using String.runes property

String.codeUnitAt( ) Function

This function returns the 16 – bit UTF – 16 code unit corresponding to the string at a particular index passed to the function as an argument.

Implementation = String.codeUnitAt( int index ) ;

Program

void main( ) 
{  
  // initializing string str
  String str = ' Let us understand codeUnits Property ' ;  
  
  // using codeUnitAt function to return the code unit at index 0
  print( str.codeUnitAt( 0 ) ) ;  
  
  // using codeUnitAt function to return the code unit at index 2
  print( str.codeUnitAt( 2 ) ) ;  
} 

Output :

32
101

String.codeUnits Property

This property returns the list of the UTF – 16 code units of the specified string.

Implementation = String. codeUnits ;

Program

void main( )
{ 
   // initializing string str
   String str = ' This tutorial teaches Runes ' ; 
  
   print( ' \n The code units are as follows : \n ' );
  
   // Using codeUnits property to print the code units of each string
   print( str.codeUnits ) ; 
}

Output :

The code units are as follows : 
 [32, 84, 104, 105, 115, 32, 116, 117, 116, 111, 114, 105, 97, 108, 32, 116, 101, 97, 99, 104, 101, 115, 32, 82, 117, 110, 101, 115, 32]

String.runes Property

This property returns an iterable of Unicode code – points of the passed string.Runes.

Implementation = String.runes

Program

void main( )
{ 
   " This teaches Runes ".runes.forEach( ( int rune ){ 
      var character = new String.fromCharCode( rune ) ; 
      print( character ) ; 
   } ) ;  
}

Output:

T
h
i
s
 
t
e
a
c
h
e
s
 
R
u
n
e
s

Related Topics

Dart Generics

Dart Generics is similar to Dart collections, which are used to store homogeneous data. As we have discussed in Dart's features, it is a language with types being optional. By default,...

4 minutes read.

Dart If statement

If statement is used to set the control on the lines of code. Using if statement, block of code is executed only if the expression in the statement returns true....

1 minute read.

Golang vs Dart

Go is the procedural programming language. It was founded in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson at Google but was launched in 2009 as the language of...

2 minutes read.

Interfaces in Dart

An interface in Dart refers to the syntax or blueprint that any class must adhere to. It basically defines the array of methods available on the object. It provides the...

3 minutes read.

Common Collection Methods

Most of the programming languages have arrays as a way to list items together. However, Dart has a collection of data structures similar to array. These are supported by the...

3 minutes read.

Lexical Scope and Closure

Lexical Scope : Lexical scope is a very important term in any programming language. It defines the scope of the variable based on the block it is contained inside. According to...

2 minutes read.

Dart Built-in Data Types

A data type defines the type of value a variable can hold, such as integer, double, or string.  Dart supports two data types:  1. Built-in data types : These are the data...

1 minute read.

Dart Object-Oriented Concepts

Dart is a programming language that supports object-oriented programming. It is focused on the objects that are real-world entities and supports all the concepts of OOPS, such as objects, classes,...

4 minutes read.

C++ vs Dart

Difference between C++ and Dart C++ is an object-oriented programming language developed in 1980 by Bjarne Stroustrup. It has wide real-world applications with various in-built functions and a very vast library...

1 minute read.

main function in Dart

The main( ) function is a predefined method in Dart that is also known as the entry-point of the program. The compiler begins the execution only when it comes across...

3 minutes read.

Dart Runes and Graphemes

Runes and Graphemes data types in Dart Runes and Graphemes Runes are the special string of Unicode UTF-32 bits that represent the special syntax. Unicode defines a unique numeric value for each...

2 minutes read.

Dart Tutorial

Dart is an open-source, structured programming language developed by Google. It is a high-level programming language that emerged in 2011, but its stable version emerged in 2017. It is largely used...

4 minutes read.

Builder Classes in Dart

Before understanding builder classes, let us understand about Flutter that makes the best use of the builder classes. Flutter is actually not a programming language, it is a software development...

6 minutes read.

Dart Iterable

Iterable is a collection of elements that are accessed sequentially. These elements are accessible using the iterator getter and stepping through the values using this getter. Let us understand the setting...

6 minutes read.

Dart Method Overriding

Before understanding method overriding, it is important to clear the concept of polymorphism. Polymorphism is derived from two Greek words 'Poly' which means many and 'morphs' which means many forms....

5 minutes read.

Dart Queues

A queue is a user-defined collection of data. It is based on the FIFO principle ( First In First Out ) which implies that the element to be inserted first,...

3 minutes read.

Dart Exception Handling

Exception Class – An exception is any runtime error that leads to abrupt termination of the program. It helps in addressing the error programmatically. It is aimed to be caught...

4 minutes read.

Dart Important Concepts

1. Anything placed in a variable is an object, and an object is an instance of a class. Numbers, functions, and null are all objects in Dart, and all these...

3 minutes read.

Dart Maps

Map is an object-based data structure that associates keys and values that can be of any data type. Every key can occur only once, while the values can be used multiple...

5 minutes read.

Dart Break and Continue

Loop statements are used to change the normal sequence of flow of the program. Dart supports two types of loop control statements: Break StatementContinue Statement Break Statement : The ‘ break ’ statement is...

4 minutes read.