String is an immutable sequence of UTF-16 code units. It represents text data and provides a robust set of built-in properties and methods for string manipulation, supporting both standard character encoding and complex Unicode scalar values.
String Literals
Dart supports multiple literal formats to accommodate different formatting and escaping requirements. Strings can be defined using single or double quotes.r creates a raw string. Raw strings ignore escape sequences (like \n or \t), treating them as literal characters.
String Interpolation
Dart evaluates expressions embedded within string literals using the$ or ${} syntax. The language implicitly invokes the toString() method on the evaluated object. The curly braces can be omitted for simple identifiers.
Concatenation
Strings can be concatenated using the+ operator. Additionally, Dart supports implicit concatenation of adjacent string literals, which is evaluated at compile time.
Immutability
Strings in Dart are strictly immutable. Once aString object is created in memory, its state cannot be altered. Any method that performs a transformation (e.g., substring, replaceAll, toLowerCase) allocates and returns a completely new String object.
Internal Representation: Code Units and Runes
Because Dart strings are UTF-16, characters within the Basic Multilingual Plane (BMP) are represented by a single 16-bit code unit. However, characters outside the BMP (such as emojis or specific mathematical symbols) require two code units, known as a surrogate pair. To safely iterate over or manipulate complex Unicode characters without splitting surrogate pairs, Dart provides therunes property, which exposes an iterable of UTF-32 code points.
Tired of Poor Dart Skills? Fix That With Deep Grasping!Learn More





