Created
June 6, 2014 04:34
-
-
Save lightxue/70c47d3425525198a6a3 to your computer and use it in GitHub Desktop.
count utf8 string length
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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