> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Dart String

A Dart `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.

```dart theme={"dark"}
String singleQuote = 'A string literal';
String doubleQuote = "Another string literal";
```

**Multiline Strings**
Triple quotes (either single or double) create multiline strings, preserving whitespace and line breaks exactly as authored in the source code.

```dart theme={"dark"}
String multiline = '''
This is a
multiline string
''';
```

**Raw Strings**
Prefixing a string literal with `r` creates a raw string. Raw strings ignore escape sequences (like `\n` or `\t`), treating them as literal characters.

```dart theme={"dark"}
String rawString = r'This will print the \n literally.';
```

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

```dart theme={"dark"}
int value = 42;
String simple = 'The value is $value';
String expression = 'The hex value is ${value.toRadixString(16)}';
```

## Concatenation

Strings can be concatenated using the `+` operator. Additionally, Dart supports implicit concatenation of adjacent string literals, which is evaluated at compile time.

```dart theme={"dark"}
// Operator concatenation
String combined = 'Hello' + ' ' + 'World';

// Adjacent literal concatenation (compile-time)
String adjacent = 'Hello' ' ' 'World';
```

## Immutability

Strings in Dart are strictly immutable. Once a `String` 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.

```dart theme={"dark"}
String original = 'Dart';
// The following creates a new string; 'original' remains 'Dart'
String modified = original.toUpperCase(); 
```

## 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 the `runes` property, which exposes an iterable of UTF-32 code points.

```dart theme={"dark"}
String emoji = '🚀';

// Length in UTF-16 code units (Returns 2, due to surrogate pair)
int unitLength = emoji.length; 

// UTF-16 code units: [55357, 56960]
List<int> codeUnits = emoji.codeUnits; 

// Length in UTF-32 code points (Returns 1)
int runeLength = emoji.runes.length; 

// UTF-32 code points: (128640)
Iterable<int> runes = emoji.runes; 
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Dart Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
