Substr does not handle unicode?

I have a unicode string
myStrig = "üöéñ and so on"
OF can print it nicely to the screen. But when I try to create an array of each separate letter by using
string letter = currentString.substr(i,1);
then some letters do not get stored in the array.

Is there a work around for this?

Thanks.
I’m on OSX 10.12 with OF 0.10

I hate these type of issues, it can be a number of things. How are you rendering those letters? And how do you know they are not stored in the array? It could be that the debugger shows something (with a certain encoding) but the actual bytes are different.

This may help:

The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

maybe helpful:


I think the problem is std::string has no sense of the encoding so substr will fail if the characters are multiple bytes (utf-8). the above links contain some hand written functions that might work and links to other libraries that are more advanced.

thank guys.

the debugger shows /033 or something similar when it should show ñ
the string does not draw to the screen via .drawString()

but ofxUnicode solved me problem

        auto text32 = ofx::TextConverter::toUTF32(currentString);
        string letter = ofx::TextConverter::toUTF8(text32[i]);
        std::cout << ofx::TextConverter::toUTF8(text32[i]) <<" letter "<<letter<<endl;
        ofSetColor(255);
        usedFont.drawString(letter,x,y);

if you are using the nightly version you can use the new ofUTF8 functions. some of them are already present in 0.9.8 but not all of them and not sure if substring was.

in any case you can do now:

auto substr = ofUTF8Substring(str, start, len);

to get a substring from an utf8 encoded string