当前位置:   article > 正文

Qt 中文字符排序 中文排序_qt汉字排序

qt汉字排序

Qt 中文字符排序

代码

#include <QDebug>
#include <QCollator>
#include <QLocale>
void test()
{
	QLocale local(QLocale::Chinese);
    QCollator collator(local);

    QStringList list;

    list << QStringLiteral("朱") << QStringLiteral("爱") << QStringLiteral("你") << QStringLiteral("好")
             << QStringLiteral("S") << QStringLiteral("中") << QStringLiteral("不");

    std::sort(list.begin(), list.end(), collator);

    for(auto it : list)
    {
        qDebug() << it;
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

运行结果

"S"
"爱"
"不"
"好"
"你"
"中"
"朱"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

QCollator和QLocale的更多用法请参考qt 文档

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/300163
推荐阅读
相关标签
  

闽ICP备14008679号