Strings
In Autolang, String represents immutable UTF-8 text. Strings provide rich inspection, slicing, and functional transformation operations.
Creation & Raw Multiline Strings
Construct strings using standard double quotes or raw multiline triple quotes ("""..."""). Raw strings preserve backslashes verbatim and support string interpolation using $variable or ${expression}.
val customer = "Acme Corp"
val orderCount = 12
// Standard interpolation
val summary = "Account ${customer} has ${orderCount} active orders."
println(summary)
// Raw multiline string (preserves backslashes without escape characters)
val queryPayload = """{
"filter": "status = 'ACTIVE'",
"path": "C:\services\logs\app.log"
}"""
println(queryPayload)Characters & String Indexing
Autolang has a first-class Char type. Indexing a string using str[index], str.charAt(index), str.first(), or str.last() yields a Char value.
val code = "ORD-920"
val firstChar: Char = code[0]
println("First char: " + firstChar) // O
println("First: " + code.first()) // O
println("Last: " + code.last()) // 0
// Character inspections
val isLetter = firstChar.isLetter()
val isDigit = code[4].isDigit()
println("First is letter: " + isLetter + ", fifth is digit: " + isDigit)Search & Validation Operations
Inspect text content with case-sensitive or case-insensitive options, prefixes, and suffixes.
val endpoint = "https://api.enterprise.com/v1/orders"
println("Has https? " + endpoint.startsWith("https://")) // true
println("Ends with orders? " + endpoint.endsWith("/orders")) // true
println("Index of v1: " + endpoint.indexOf("v1")) // 27
// Case-insensitive search
val greeting = "Welcome Enterprise User"
val containsUser = greeting.contains("user", true)
println("Contains user (ignore case): " + containsUser) // trueText Manipulation & Slicing
Strings are immutable. Methods like take, drop, trim, and replace return new String instances.
val rawToken = " Bearer tok_abc123456xyz "
val token = rawToken.trim().removePrefix("Bearer ")
println("Clean token: " + token)
println("Prefix: " + token.take(7)) // tok_abc
println("Suffix: " + token.takeLast(6)) // 123xyz
// Splitting with multiple delimiters
val timestamp = "2026-10-03T14:30:00Z"
val components = timestamp.split("T", ":")
println("Hour component: " + components[1]) // 14Functional Pipelines on Strings
Strings can be transformed and inspected using higher-order lambda functions directly.
val serial = "AB-901-XZ"
// Predicates
val allAlphanumeric = serial.all { it.isLetterOrDigit() || it == '-' }
println("Valid serial: " + allAlphanumeric) // true
// Functional filter
val digitsOnly = serial.filter { it.isDigit() }
println("Digits only: " + digitsOnly) // 901
// Count occurrences
val hyphenCount = serial.count { it == '-' }
println("Hyphen count: " + hyphenCount) // 2StringBuilder
For high-throughput string construction, StringBuilder provides efficient in-place buffer mutation.
val builder = StringBuilder("REPORT:")
builder.append(" status=OK")
builder.append(", records=")
builder.append(250)
println(builder.toString()) // REPORT: status=OK, records=250