×

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 Keywords

Keywords are the reserved words of a programming language, and they have a special meaning that comes defined by the language. These cannot be used as an identifier, and all...

1 minute read.

Dart Static Members

Static Members in Dart Static members are the members of the class declared using the 'static' keyword. the static members have the following characteristics :  All the objects of the class having...

3 minutes read.

Dart Type Test Operators

Type Test Operators in Dart These operators are used to check the types of expressions at runtime. Dart is a typed language, and we often want to assert that a value...

1 minute read.

Rust vs Dart

Rust is a system-level programming language that stands next to C ++ in terms of syntax, but offers greater speed and memory security. Dart, on the other hand, is an...

2 minutes read.

Dart Recursion

Recursion is one of the most important and interesting concepts in any programming language. It can be defined as a process in which a function calls itself directly or indirectly....

5 minutes read.

Dart Anonymous Function

Dart functions are the user defined functions that are designed to perform specific task. The use case of the functions is that they can be directly called any number of...

3 minutes read.

Typedef in Dart

In Dart, typedef is used to generate a function type that we can use as a type annotation for declaring variables and return types of the function type. An alias...

4 minutes read.

Dart Construtors

Constructors are the very important concept in any programming language. They are the special functions created in the classes to allocate memory to the objects of that class when created...

4 minutes read.

Dart Comments

Comments are the statements that are used to enhance the readability and understandability of the code. The compiler does not execute these lines. It simply ignores these comments when it scans...

2 minutes read.

Dart Operators Precedence and Associativity

Precedence of operators determines the order in which the operators are evaluated if they are grouped together in a sentence. If two operators share an operand then the one with...

5 minutes read.

Dart Objects

Apart from the built-in data types, Dart offers some other data types that have a special role to play. One of them is Objects.  Objects Objects are the foundation of the...

3 minutes read.

Dart Installation Guide

There are various ways of compiling and running an application created in Dart, either by compiling the Dart code to JavaScript using the Dart2js tool or by running on the...

3 minutes read.

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-else statement

In the previous section, we studied about if statements in detail. If – block is executed when the condition evaluates to true, else if the condition evaluates to false, then...

1 minute read.

Dart Assignment Operator

Assignment operators are the operators that assign value to the variables. The value on the right-hand side is assigned to the variable on the left-hand side. We can also use...

4 minutes read.

Unit Testing in Dart

Typing testing ensures that your app keeps working as you add more features or change existing functionality. Unit testing helps to confirm the behavior of a single function, method, or...

4 minutes read.

Dart Packages

Every programming language has some in-built functions stored inside the header files that makes the task much easier for the programmer. The Dart Packages refer to the compilation of a...

4 minutes read.

Dart Miscellaneous Operators

Apart from the operators we studied so far, Dart provides some more operators which are as follows : Conditional OperatorCascade Notations Conditional Operators These are the operators that help in evaluating the expression...

1 minute read.

Dart Basics

Dart, as earlier mentioned multiple times, is very similar to C, C++ and Java. It is an object-oriented, garbage collecting and class-based programming language. Let’s look further and see what Dart has...

10 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.