Mojo package
string
The string package provides comprehensive Unicode string handling functionality for Mojo.
This package implements Unicode-aware string types and operations, with UTF-8 support. It includes efficient implementations for string manipulation, formatting, and Unicode operations while maintaining memory safety and performance.
Key Components:
- String: The main string type supporting UTF-8 encoded text,
- StringSlice: Memory-efficient string view type for zero-copy operations
- Codepoint: Unicode code point handling and operations
- Format: String formatting and interpolation utilities
Core Features:
- Unicode support with UTF-8 encoding
- Efficient string slicing and views
- String formatting and interpolation
- Memory-safe string operations
- Unicode case conversion
- Unicode property lookups and validation
Example:
    # Basic string creation and manipulation
    var s = "Hello, 世界" # runtime type is `String`
    var slice = s[0:5] # "Hello"
    # Unicode-aware operations
    for c in s.codepoints():
        print(c.to_uppercase())
    # String formatting
    var name = "Mojo"
    var formatted = "Hello, {name}!"Note:
String stores data using UTF-8, and all operations (unless clearly noted) are intended to be fully Unicode compliant and maintain correct UTF-8 encoded data. A handful of operations are known to not be Unicode / UTF-8 compliant yet, but will be fixed as time permits.
Modules
- codepoint: Unicode codepoint handling.
- format: String formatting utilities for Mojo.
- string: The coreStringtype implementation for Mojo.
- string_slice: TheStringSlicetype implementation for efficient string operations.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!
