get_char


Description:

public unichar get_char (long index = 0)

Converts a sequence of bytes encoded as UTF-8 to a Unicode character.

If index does not point to a valid UTF-8 encoded character, results are undefined. If you are not sure that the bytes are complete valid Unicode characters, you should use string.get_char_validated instead.

Example: Utf8-handling, get_char:

public static int main (string[] args) {
string wisdom = "水は方円の器に従い、人は善悪の友による。";

// Output: ``水は方円の器に従い、人は善悪の友による。``
for (int i = 0; i < wisdom.length; i++) {
if (wisdom.valid_char (i)) {
print (wisdom.get_char (i).to_string ());
}
}
print ("\n");
return 0;
}

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

Parameters:

index

a byte offset to a unicode character encoded as UTF-8

Returns:

the resulting character