Strings
Strings in Draft are UTF-8 encoded and immutable.
String Literals
Section titled “String Literals”@simple = "Hello, World!"@empty = ""@multiline = "Line 1Line 2Line 3"String Interpolation
Section titled “String Interpolation”@name = "World"@greeting = "Hello, {@name}!"@// Result: "Hello, World!"String Properties
Section titled “String Properties”@text = "Hello"@text#length @// 5@text#is_empty @// false@text#chars @// Array of characters@text#bytes @// Array of bytesString Methods
Section titled “String Methods”Case Conversion
Section titled “Case Conversion”@"Hello"#upper() @// "HELLO"@"Hello"#lower() @// "hello"@"hello"#capitalize() @// "Hello"@"hello world"#title_case() @// "Hello World"Trimming
Section titled “Trimming”@" hello "#trim() @// "hello"@" hello "#trim_start() @// "hello "@" hello "#trim_end() @// " hello"Searching
Section titled “Searching”@"Hello World"#contains("World") @// true@"Hello World"#starts_with("Hello") @// true@"Hello World"#ends_with("World") @// true@"Hello World"#index_of("World") @// 6@"Hello World"#last_index_of("l") @// 9Substrings
Section titled “Substrings”@"Hello World"#substring(0, 5) @// "Hello"@"Hello World"#slice(6) @// "World"Splitting and Joining
Section titled “Splitting and Joining”@"a,b,c"#split(",") @// ["a", "b", "c"]@"Hello World"#split(" ") @// ["Hello", "World"]@["a", "b", "c"]#join(",") @// "a,b,c"Replacing
Section titled “Replacing”@"Hello World"#replace("World", "Draft") @// "Hello Draft"@"aaa"#replace("a", "b") @// "bbb"Padding
Section titled “Padding”@"hello"#pad_start(10) @// " hello"@"hello"#pad_end(10) @// "hello "@"42"#pad_start(5, "0") @// "00042"Reversing
Section titled “Reversing”@"hello"#reverse() @// "olleh"Character Operations
Section titled “Character Operations”@char = 'A'@char#is_upper() @// true@char#is_lower() @// false@char#is_digit() @// false@char#is_alpha() @// true@char#is_alphanumeric() @// true@char#is_whitespace() @// false@char#to_lower() @// 'a'@char#to_upper() @// 'A'String Iteration
Section titled “String Iteration”for @char in "Hello" write(@char)fin for.Raw Strings
Section titled “Raw Strings”Strings without escape processing:
@path = r"C:\Users\Alice\Documents"@regex = r"^\d+$"String Building
Section titled “String Building”For efficient string concatenation:
@builder = String::new()@builder#append("Hello")@builder#append(" ")@builder#append("World")@result = @builder#to_string() @// "Hello World"Format Strings
Section titled “Format Strings”@formatted = format("Hello, {0}! You are {1} years old.", "Alice", 30)@// "Hello, Alice! You are 30 years old."String to Number Conversion
Section titled “String to Number Conversion”@num = "42"#to_int() @// 42@flt = "3.14"#to_float() @// 3.14Number to String Conversion
Section titled “Number to String Conversion”@str = 42#to_string() @// "42"@flt_str = 3.14#to_string() @// "3.14"Multiline Strings
Section titled “Multiline Strings”@text = """This is amultiline stringwith preserved formatting."""String Comparison
Section titled “String Comparison”@"a" == @"b" @// false@"a" != @"b" @// true@"a" < @"b" @// true (lexicographic)@"abc" == @"abc" @// trueNext Steps
Section titled “Next Steps”Learn about Modules for code organization.
