FR
PréludeChargé par défaut — aucun import nécessaire.

Extended string operations

Synopsis
clampNat : Int -> Nat
takeCs : Int -> List Char -> List Char
dropCs : Int -> List Char -> List Char
slice : Int -> Int -> String -> String

The code points in the half-open range [start, end), with start and end clamped to the string's bounds: String.slice 1 4 "abcdef" = "bcd", String.slice (0 - 5) 2 "abc" = "ab".

substring : Int -> Int -> String -> String

len code points starting at start: String.substring 2 3 "abcdef" = "cde". Equal to slice start (start + len).

contains : String -> String -> Bool

Does the string contain needle as a substring?

indexOf : String -> String -> Maybe Int

The code-point index of the first occurrence of needle, or Nothing. The empty needle is found at index 0.

repeat : Int -> String -> String

n copies of the string concatenated (empty if n ≤ 0): String.repeat 3 "ab" = "ababab".

padLeft : Int -> Char -> String -> String

Pad on the LEFT with fill up to at least width code points (returns the string unchanged if it is already that wide): String.padLeft 5 '0' "42" = "00042".

padRight : Int -> Char -> String -> String

Pad on the RIGHT with fill up to at least width code points.

replace : String -> String -> String -> String

Replace every non-overlapping occurrence of old with new. An empty old leaves the string unchanged. String.replace "ab" "X" "abcab" = "XcX".

splitOn : String -> String -> List String

Split on a (possibly multi-character) separator, keeping empty chunks: String.splitOn ", " "a, b, c" = ["a", "b", "c"], String.splitOn ":" "a::b" = ["a", "", "b"]. An empty separator yields the whole string as one chunk.