Std\String
String – string manipulation and conversion.
Provides utilities for searching, transforming, splitting, and
converting strings. Iterator-returning functions (split, lines,
chars) use O(1) memory per element.
Functions
Section titled “Functions”length : String -> Int
Section titled “length : String -> Int”Returns the length of the string in bytes.
import length from Std\String inlength "hello" # => 5isEmpty : String -> Bool
Section titled “isEmpty : String -> Bool”Returns true if the string has zero length.
import isEmpty from Std\String inisEmpty "" # => trueisEmpty "hi" # => falsetoUpperCase : String -> String
Section titled “toUpperCase : String -> String”Convert all characters to uppercase.
import toUpperCase from Std\String intoUpperCase "hello" # => "HELLO"toLowerCase : String -> String
Section titled “toLowerCase : String -> String”Convert all characters to lowercase.
import toLowerCase from Std\String intoLowerCase "HELLO" # => "hello"trim : String -> String
Section titled “trim : String -> String”Remove leading and trailing whitespace.
import trim from Std\String intrim " hello " # => "hello"indexOf : String -> String -> Int
Section titled “indexOf : String -> String -> Int”Return the index of the first occurrence of needle, or -1 if not found.
import indexOf from Std\String inindexOf "hello world" "world" # => 6contains : String -> String -> Bool
Section titled “contains : String -> String -> Bool”Returns true if str contains needle.
import contains from Std\String incontains "hello world" "world" # => truestartsWith : String -> String -> Bool
Section titled “startsWith : String -> String -> Bool”Returns true if str starts with prefix.
import startsWith from Std\String instartsWith "hello" "hel" # => trueendsWith : String -> String -> Bool
Section titled “endsWith : String -> String -> Bool”Returns true if str ends with suffix.
import endsWith from Std\String inendsWith "hello.txt" ".txt" # => truesubstring : String -> Int -> Int -> String
Section titled “substring : String -> Int -> Int -> String”Extract a substring from index start (inclusive) to end (exclusive).
import substring from Std\String insubstring "hello" 1 4 # => "ell"replace : String -> String -> String -> String
Section titled “replace : String -> String -> String -> String”Replace all occurrences of old with new.
import replace from Std\String inreplace "aabaa" "a" "x" # => "xxbxx"split : String -> String -> Iterator a
Section titled “split : String -> String -> Iterator a”Split a string by a delimiter. Returns an Iterator String.
import split from Std\String inlet iter = split "a,b,c" "," in# consume with iterator protocoljoin : String -> [a] -> String
Section titled “join : String -> [a] -> String”Join a sequence of strings with a separator.
import join from Std\String injoin ", " ["a", "b", "c"] # => "a, b, c"charAt : String -> Int -> Int
Section titled “charAt : String -> Int -> Int”Returns the character code (Int) at the given index.
import charAt from Std\String incharAt "ABC" 0 # => 65padLeft : Int -> String -> String -> String
Section titled “padLeft : Int -> String -> String -> String”Pad str on the left with pad until it reaches width.
import padLeft from Std\String inpadLeft 5 "0" "42" # => "00042"padRight : Int -> String -> String -> String
Section titled “padRight : Int -> String -> String -> String”Pad str on the right with pad until it reaches width.
import padRight from Std\String inpadRight 5 "." "hi" # => "hi..."reverse : String -> String
Section titled “reverse : String -> String”Reverse a string.
import reverse from Std\String inreverse "hello" # => "olleh"repeat : Int -> String -> String
Section titled “repeat : Int -> String -> String”Repeat a string n times.
import repeat from Std\String inrepeat 3 "ab" # => "ababab"take : Int -> String -> String
Section titled “take : Int -> String -> String”Take the first n characters of a string.
import take from Std\String intake 3 "hello" # => "hel"drop : Int -> String -> String
Section titled “drop : Int -> String -> String”Drop the first n characters of a string.
import drop from Std\String indrop 3 "hello" # => "lo"count : String -> String -> Int
Section titled “count : String -> String -> Int”Count the number of non-overlapping occurrences of needle in str.
import count from Std\String incount "ababa" "ab" # => 2lines : String -> Iterator a
Section titled “lines : String -> Iterator a”Split a string into lines. Returns an Iterator String.
import lines from Std\String inlet iter = lines "a\nb\nc" in# consume with iterator protocolunlines : [a] -> String
Section titled “unlines : [a] -> String”Join a sequence of strings with newline separators.
import unlines from Std\String inunlines ["a", "b", "c"] # => "a\nb\nc"chars : String -> Iterator a
Section titled “chars : String -> Iterator a”Returns an Iterator over individual characters of the string.
import chars from Std\String inlet iter = chars "hello" in# consume with iterator protocolfromChars : [a] -> String
Section titled “fromChars : [a] -> String”Build a string from a sequence of character codes.
import fromChars from Std\String infromChars [72, 105] # => "Hi"toInt : String -> Int
Section titled “toInt : String -> Int”Parse a string as an integer.
import toInt from Std\String intoInt "42" # => 42toFloat : String -> Float
Section titled “toFloat : String -> Float”Parse a string as a float.
import toFloat from Std\String intoFloat "3.14" # => 3.14