String module

split_from_left

procedure · 2 overloadsSource

Splits s at the first byte. Returns whether it was found, the part before it and the part after it.

split_from_left :: (
    s: string,
    byte: u8
) -> (found: bool, left: string, right: string)

When the byte is not found the result is false, all of s and an empty string. Both parts point into s.

Parameters

s: string
byte: u8

Returns

found: bool
left: string
right: string
ExampleOpen in playground ↗
found, left, right := split_from_left("key=a=b", #char "=");
assert(found && left == "key" && right == "a=b");

found, left, right = split_from_left("none", #char "=");
assert(!found && left == "none" && right == "");
split_from_left :: (
    s: string,
    separator: string
) -> (found: bool, left: string, right: string)

Splits s at the first separator. Returns whether it was found, the part before it and the part after it.

When the separator is not found, or is empty, the result is false, all of s and an empty string.

Parameters

s: string
separator: string

Returns

found: bool
left: string
right: string
ExampleOpen in playground ↗
found, left, right := split_from_left("a::b::c", "::");
assert(found && left == "a" && right == "b::c");

See also