Skip to content

Instantly share code, notes, and snippets.

@lightxue
Created June 6, 2014 04:34
Show Gist options
  • Save lightxue/70c47d3425525198a6a3 to your computer and use it in GitHub Desktop.
Save lightxue/70c47d3425525198a6a3 to your computer and use it in GitHub Desktop.
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++;
}
return cnt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment