StringSearch.split

Splits str into at most n slices on each occurrence of delim. collapse indicates whether to collapse consecutive occurrences to a single one to prevent producing empty slices.

  1. TElem[] split(TElem[] slices, TElem str, Char delim, uint n, bool collapse)
    struct StringSearch(bool wide_char = false)
    static
    TElem[]
    split
    (
    TElem
    )
    (
    ref TElem[] slices
    ,
    TElem str
    ,,
    uint n = 0
    ,
    bool collapse = false
    )
  2. TElem[] split(TElem[] slices, TElem str, Char[] delims, uint n, bool collapse)

Parameters

slices TElem[]

resulting slices buffer

str TElem

input string

delim Char

delimiter character

n uint

maximum number of slices; set to 0 to indicate no limit

collapse bool

set to true to collapse consecutive occurrences to prevent producing empty "slices"

Return Value

Type: TElem[]

the resulting slices

Examples

cstring[] slices;

test!("==")(StringSearch!().split(slices, "a;b;c", ';'),
            ["a", "b", "c"][]);
test!("==")(StringSearch!().split(slices, "a;b;c", '.'),
            ["a;b;c"][]);
test!("==")(StringSearch!().split(slices, "abc;", ';'),
            ["abc", ""][]);
test!("==")(StringSearch!().split(slices, ";abc;", ';'),
            ["", "abc", ""][]);
test!("==")(StringSearch!().split(slices, "a;;bc", ';'),
            ["a", "", "bc"][]);


test!("==")(StringSearch!().split(slices, "a;b;c", ';', 2),
            ["a", "b"][]);

test!("==")(StringSearch!().split(slices, "abc;", ';', 0, true),
            ["abc"][]);
test!("==")(StringSearch!().split(slices, ";abc;", ';', 0, true),
            ["abc"][]);
test!("==")(StringSearch!().split(slices, "a;;bc", ';', 0, true),
            ["a", "bc"][]);

mstring[] mslices;
test!("==")(StringSearch!().split(slices, "a;b;c".dup, ';'),
            ["a", "b", "c"][]);

Meta