substring is not working for Korean

HI,

I want to split by word count

if str is “I want to split by word count”, i make a new str to 10 characters by str

example

“I want to split by word count” -> “I want to”

but if the str is Korean words, i can’t do it

**my code is
std::string name = “오버헤드 케이블 트라이셉스 익스텐션”;
name = name.substr;
CCLog);
output log is
오버헤드 케이블 트라\354

and it is not view on CCLabel**

please help me!

thank you

you first have to get the right UTF8 string length.
try the function below.

int getUTF8Count(const char * UTF8String)
{
int lastStrPoint = 0;
int len = strlen(UTF8String);
int count = 0;
while (len>lastStrPoint) {
int nLen = 1;
int lastlen = len - lastStrPoint;
while(lastlen>1&&0x80 == (0xC0 & UTF8String[lastStrPoint+nLen]))
{
nLen;
if {
break;
}
}
lastStrPoint
= nLen;
count
+;
}
return count;
}

小 苏 wrote:

you first have to get the right UTF8 string length.
try the function below.
>
int getUTF8Count(const char * UTF8String)
{
int lastStrPoint = 0;
int len = strlen(UTF8String);
int count = 0;
while (len>lastStrPoint) {
int nLen = 1;
int lastlen = len - lastStrPoint;
while(lastlen>1&&0x80 == (0xC0 & UTF8String[lastStrPoint+nLen]))
{
nLen;
if {
break;
}
}
lastStrPoint
= nLen;
count
+;
}
return count;
}

Thanks 小 苏

Is resolved ^^