自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

關(guān)于 Qt MeeGo 中文字符串排序

移動(dòng)開(kāi)發(fā)
本文講解的是關(guān)于 Qt MeeGo 中文字符串排序的實(shí)例,本篇文章可以幫你復(fù)習(xí)Qt類。請(qǐng)看內(nèi)容。

本文講解的是關(guān)于 Qt MeeGo 中文字符串排序的實(shí)例,Qt類中的qSort()函數(shù)提供了對(duì)字符串的排序功能。要利用qSort為中文進(jìn)行排序則需要我們提供一個(gè)針對(duì)中文比較規(guī)則的比較器。

Meego Touch Framework 中的MCollator實(shí)現(xiàn)了該功能。更準(zhǔn)確地說(shuō)是MCollator實(shí)現(xiàn)了所有國(guó)家語(yǔ)言的排序功能。

簡(jiǎn)單的用法如下。

  1. MLocale loc; // 這里設(shè)置對(duì)應(yīng)國(guó)家的語(yǔ)言和排序方法  
  2. MCollator comp = loc.collator();  
  3. QStringList stringList;  
  4. //add contents to stringList  
  5. qSort(stringList.begin(), stringList.end(), comp); // sorts the list 

中文有按照拼音(pinyin)和筆畫(huà)(stroke)兩種排序方式.

所以我們構(gòu)造MLocale的時(shí)候可以用

//根據(jù)拼音或筆畫(huà)選擇一種

  1. MLocale loc(“zh_CN@collation=pinyin”);  
  2. MLocale loc(“zh_CN@collation=stroke”); 

完整的代碼如下

  1. #include <QCoreApplication> 
  2. #include <QObject> 
  3. #include <MLocale> 
  4. #include <MCollator> 
  5. #include <QStringList> 
  6. #include <QDebug> 
  7. #include <QTextCodec> 
  8. int main(int argc,char *argv[]){  
  9. QCoreApplication app(argc,argv);  
  10. //MLocale loc(locale_name);  
  11. MLocale loc(“zh_CN@collation=pinyin”);  
  12. MCollator mcomp = loc.collator();  
  13. QTextCodec *tc=QTextCodec::codecForName(“utf8″);  
  14. QTextCodec::setCodecForCStrings(tc);  
  15. QStringList stringList;  
  16. //stringList << “bb” << “da” << “aa” << “ab”;  
  17. stringList<<”黨”<<”的”<<”政”<<”策”<<”亞”<<”克”<<”西”;  
  18. qSort(stringList.begin(), stringList.end(), mcomp);  
  19. qDebug()<<stringList;  

如果是按拼音排序輸出將是 (“策”, “黨”, “的”, “克”, “西”, “亞”, “政”).

而按筆畫(huà)排序輸出將是 (“西”, “克”,”的”,”政”, “黨”, “策”, “亞”).

需要注意的是編譯該代碼需要在你的工程文件.pro中加入CONFIG+=meegotouch。

小結(jié):關(guān)于關(guān)于 Qt MeeGo 中文字符串排序的內(nèi)容介紹完了,如果你還是不怎么清楚,多參考Qt類,會(huì)幫你解決更多的問(wèn)題。希望本文對(duì)你有所幫助。

責(zé)任編輯:zhaolei 來(lái)源: 互聯(lián)網(wǎng)
相關(guān)推薦

2024-03-11 06:05:00

C++字符串

2009-11-26 16:26:32

PHP字符串mbstr

2009-11-26 16:43:11

PHP截取中文字符串

2010-03-05 16:09:44

Python中文字符

2010-02-02 16:49:32

C++中文字符

2009-12-03 10:09:36

linux添加字體中文字體

2009-12-01 15:41:16

PHP substr截

2009-11-27 09:55:11

PHP截取中文字符

2010-07-14 16:21:48

Perl

2011-01-11 10:05:29

Linux中文字體

2021-04-13 14:36:00

鴻蒙HarmonyOS應(yīng)用

2009-11-27 09:30:58

PHP函數(shù)mb_str

2010-11-26 11:08:20

MySQL字符串

2010-09-01 14:20:19

CSS排版

2011-06-03 13:03:03

JAVA

2009-11-16 17:59:13

PHP數(shù)組轉(zhuǎn)字符串

2011-06-22 18:08:01

Qt TCP 字符串

2010-02-04 09:37:31

2010-03-15 15:51:35

Ubuntu 8.04

2011-08-23 14:26:07

Lua字符串
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)