index_of_char
Description:
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. |