QT 中文字符串排序
来源:互联网 发布:陕西师大网络教育平台 编辑:程序博客网 时间:2024/05/16 11:08
MeeGo 中文字符串排序
转自:http://www.cuteqt.com/blog/?p=1934
Qt类中的qSort()函数提供了对字符串的排序功能。要利用qSort为中文进行排序则需要我们提供一个针对中文比较规则的比较器。
Meego Touch Framework 中的MCollator实现了该功能。更准确地说是MCollator实现了所有国家语言的排序功能。
简单的用法如下。
MLocale loc; // 这里设置对应国家的语言和排序方法
MCollator comp = loc.collator();QStringList stringList;
//add contents to stringList
qSort(stringList.begin(), stringList.end(), comp); // sorts the list
中文有按照拼音(pinyin)和笔画(stroke)两种排序方式.
所以我们构造MLocale的时候可以用
//根据拼音或笔画选择一种
MLocale loc(“zh_CN@collation=pinyin”);
MLocale loc(“zh_CN@collation=stroke”);
完整的代码如下
#include <QCoreApplication>
#include <QObject>
#include <MLocale>
#include <MCollator>
#include <QStringList>
#include <QDebug>
#include <QTextCodec>int main(int argc,char *argv[]){
QCoreApplication app(argc,argv);
//MLocale loc(locale_name);
MLocale loc(“zh_CN@collation=pinyin”);
MCollator mcomp = loc.collator();QTextCodec *tc=QTextCodec::codecForName(“utf8″);
QTextCodec::setCodecForCStrings(tc);
QStringList stringList;
//stringList << “bb” << “da” << “aa” << “ab”;
stringList<<”党”<<”的”<<”政”<<”策”<<”亚”<<”克”<<”西”;qSort(stringList.begin(), stringList.end(), mcomp);
qDebug()<<stringList;
}
如果是按拼音排序输出将是 (“策”, “党”, “的”, “克”, “西”, “亚”, “政”).
而按笔画排序输出将是 (“西”, “克”,”的”,”政”, “党”, “策”, “亚”).
需要注意的是编译该代码需要在你的工程文件.pro中加入CONFIG+=meegotouch.
- QT 中文字符串排序
- QT meeGo 中文字符串排序
- qt 中文排序
- 【QT】字符串中文
- 中文字符串排序解决方案
- QT中文字符串个数问题
- qt & qt creator 中文字符串查找问题
- Java字符串排序中文+数字
- java中的中文字符串排序
- Qt中文字符串的设置方法
- Qt中文字符串的设置方法
- QT中用正则表达式匹配中文字符串
- QT:QString 字符串和中文字符编码
- QT中文乱码问题(字符串变量)
- java中文字符串按拼音排序 代码
- java中文字符串按拼音排序代码
- Java对中文字符串排序处理
- Java提高:中文字符串排序的瑕疵
- mini2440定制内核 ActiveSync问题
- WCF中方法返回泛型类,客户端生成方法将返回类型自动改名
- php读取Access数据库
- linux PPP数据收发流程
- 几个输入函数
- QT 中文字符串排序
- Linux系统调用--fcntl函数详解
- introduces security concepts step by step with a sample (a story)
- ORA-12537: TNS:connection closed
- js获取url参数
- 删除svn隐藏目录SHELL命令(for windows and unix-like system)
- 打开小孔子内容管理系统时候,提示“无法打开项目文件“***.csproj”.此安装不支持该项目类型”
- adobe公司实习题
- 引用System.Runtime.Serialization.Json 提示 命名空间 不存在类型或命名空间名称 json