比较国际字符串
Comparing international strings
我想做的是比较2个具有特殊字符(法语)的qstring
首先我从服务器收到保存在txtInfo中的json数据
txtInfo = "Présenter";
当我有这样的条件时它不会工作(它不会设置状态)
if (txtInfo == "Présenter"){
m_appState = 8;
m_appStateString = AppStatesArray[m_appState];
}
else {
m_appState = -1;
m_appStateString = "UNKNOWN";
}
我错过了什么?如果我想比较的不是法语而是汉语呢?
非常感谢
由于Qt 5 QString的operator==
在被比较的字符数组上执行fromUtf8
转换。但是,如果源文件(.cpp)不使用utf8,则需要构建自己的QString。
取决于你的源文件(.cpp)的编码:
Utf8:
QString compared = QString::fromUtf8("Présenter");
if (txtInfo == QString::fromUtf8("Présenter")){
本地8位:
QString compared = QString::fromLocal8Bit("Présenter");
if (txtInfo == QString::fromUtf8("Présenter")){
为了100%的正确性,不要忘记规范化你的字符串:
txtInfo = txtInfo.normalized(QString::NormalizationForm_D);
QString compared = /* the correct form for you */;
if (txtInfo == compared.normalized(QString::NormalizationForm_D)){
相关文章:
- 为什么字符串比较的 == 运算符相对于任一字符串长度线性时间(似乎)?
- 字符串比较中的意外输出
- 如何执行不区分大小写的字符串比较?
- 使用 getline(cin, var) 两次在进行字符串比较时会产生错误 (==)
- <<运算符优先级与字符串比较
- ">"运算符和"<"运算符如何进行字符串比较?
- Qt C++11 字符串通过子字符串比较列出交集
- std::out_of_range字符串比较中的异常
- 我正在尝试从输入文件中读取,然后使用它们的子字符串比较字符串的特定部分
- 字符* 与uint8_t的字符串比较
- 用字符串 c++ 比较对向量的元素
- 使用循环进行词典字符串比较
- 如何为C++映射创建自己的字符串比较对象
- 不带比较()的字符串比较
- 与 IF 语句C++的字符串比较?
- 字符串比较在与变量一起使用时给出不同的输出
- 更快的字符串比较排序,用于唯一()
- C 字符串比较“祝您好运”&gt;“再见”
- C 奇怪的行为和字符串比较
- 子字符串与 std::memcmp 或字符串::比较的比较