[ CCode ( cname = "g_utf8_strlen" ) ]
public int char_count (ssize_t max = -1)
Computes the length of the string in characters, not including the terminating nul character.
If the max
'th byte falls in the middle of a character, the last (partial) character is not counted.
Example: Utf8-handling, length in characters:
public static int main (string[] args) {
string str = "Ἀρχιμήδης";
int letters = str.char_count ();
int bytes = str.length;
// Output: ``letters: 9, bytes: 19``
print ("letters: %d, bytes: %d\n", letters, bytes);
return 0;
}
valac --pkg glib-2.0 string.char_count.vala
max |
the maximum number of bytes to examine. If |
p |
pointer to the start of a UTF-8 encoded string |
the length of the string in characters |