index_of_char


Description:

public int index_of_char (unichar c, int start_index = 0)

Finds the leftmost occurrence of the given Unicode character in a UTF-8 encoded string.

Example: Find the leftmost occurrence of the given unichar:

public static int main (string[] args) {
string haystack = ". -..- - . .-. -- .. -. .- - .";
int index = 0;

// Output: ``0 3 4 9 11 13 18 19 22 24 29 -1``
do {
index = haystack.index_of_char ('.', index);
print ("%d ", index);
} while (index++ >= 0);
print ("\n");
return 0;
}

valac --pkg glib-2.0 string.index_of_char.vala

Parameters:

c

a unicode character

start_index

the starting position for the search in bytes.

Returns:

the byte index of the first occurrence of the character, or -1 if the character does not occur.