4

I am working with C++ and QT and have a problem with german umlauts. I have a QString like "wir sind müde" and want to change it to "wir sind müde" in order to show it correctly in a QTextBrowser.

I tried to do it like this:

s = s.replace( QChar('ü'), QString("ü"));

But it does not work.

Also

 s = s.replace( QChar('\u00fc'), QString("ü"))

does not work.

When I iterate through all characters of the string in a loop, the 'ü' are two characters.

Can anybody help me?

4

2 回答 2

7

QStrings 是 UTF-16。

QString 存储一串 16 位 QChar,其中每个 QChar 对应一个 Unicode 4.0 字符。(代码值高于 65535 的 Unicode 字符使用代理对存储,即两个连续的 QChar。)

所以试试

//if ü is utf-16, see your fileencoding to know this
s.replace("ü", "ü")

//if ü if you are inputting it from an editor in latin1 mode
s.replace(QString::fromLatin1("ü"), "ü");
s.replace(QString::fromUtf8("ü"), "ü"); //there are a bunch of others, just make sure to select the correct one
于 2011-10-18T11:23:55.400 回答
1

üUnicode中有两种不同的表示形式:

  • 单点00FC(带分音符号的拉丁小写字母 U)
  • 序列0075(拉丁文小写字母 U)0308(结合分音符号)

你应该检查两者。

于 2011-10-18T11:38:49.833 回答