QString和德语的小写字母

QString and german umlauts

本文关键字:小写字 德语 QString      更新时间:2023-10-16

我正在用c++和QT工作,并有一个问题与德国变音符。我有一个像"wir sind m"的QString,并希望将其更改为"wir sind m",以便在QTextBrowser中正确显示它。

我试着这样做:

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

但它不工作。

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

不工作

当我在循环中遍历字符串的所有字符时,'ü'是两个字符。

有人能帮我吗?

qstring为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

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

  • 单点00FC(拉丁小写字母U WITH DIAERESIS)
  • 序列0075(拉丁小写字母U) 0308 (combined DIAERESIS)