Skip to content

Instantly share code, notes, and snippets.

@lightxue
lightxue / utf8len.c
Created June 6, 2014 04:34
count utf8 string length
int utf8len(const char * s, int len)
{
int cnt = 0;
int i = 0;
while (i < len) {
if ((s[i] & 0xc0) != 0x80) {
cnt++;
}
i++;
}