ANSI to UTF8
Janusch
unknown at unknown.tld
Mon Jan 31 09:08:33 PST 2011
Hello!
I'm trying to convert ANSI characters to UTF8 that but it doesn't
work correctly.
I used the following:
void main() {
writeln(convertToUTF8("ä"));
}
string convertToUTF8(string text) {
string result;
for (uint i=0; i<text.length; i++) {
char ch = text[i];
if (ch < 0x80) {
result ~= ch;
} else {
result ~= 0xC0 | (ch >> 6);
result ~= 0x80 | (ch & 0x3F);
}
}
return result;
}
But writeln doesn't print anything (only a blank line), but not my
character. The same problem exists for similar characters like ü or ö.
Is there anything I'm doing wrong?
More information about the Digitalmars-d-learn
mailing list