StringSearch.locateChar

Locates the first occurence of value within the first length characters of str. If greater, length is truncated to the length of str.

  1. size_t locateChar(Char[] str, Char value, size_t start, size_t length)
    struct StringSearch(bool wide_char = false)
    static
    size_t
    locateChar
    (
    in Char[] str
    ,,
    size_t start
    ,
    size_t length
    )
  2. size_t locateChar(Char[] str, Char value, size_t start)

Parameters

str Char[]

string to search for value

value Char

element value to find

start size_t

start index

length size_t

number of elements to examine

Return Value

Type: size_t

the index of the first element with value "value" or the index of the last examined element + 1

Examples

test!("==")(StringSearch!().locateChar("Hello", 'l', 5, size_t.max), 5);
test!("==")(StringSearch!().locateChar("Hello", 'l', 2, size_t.max), 2);
test!("==")(StringSearch!().locateChar("Hello", 'l', 3, size_t.max), 3);
test!("==")(StringSearch!().locateChar("Hello", 'o', 5, size_t.max), 5);
test!("==")(StringSearch!().locateChar("Hello", 'o', 4, size_t.max), 4);
test!("==")(StringSearch!().locateChar("Hello", 'o', 0, size_t.max), 4);
// Test searches in a limited region of the input string
test!("==")(StringSearch!().locateChar("Hello", 'l', 0, 0), 0);
test!("==")(StringSearch!().locateChar("Hello", 'l', 0, 2), 2);
test!("==")(StringSearch!().locateChar("Hello", 'l', 0, 3), 2);

Meta