`
dubinwei
  • 浏览: 56179 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

sqlite中文排序小诀窍

阅读更多
public class PinyinBiao{       
    private String[] name = { "zuo", "zun", "zui", "zuan", "zu", "zou",              
                               "zong", "zi", "zhuo", "zhun", "zhui", "zhuang", "zhuan",              
                               "zhuai", "zhua", "zhu", "zhou", "zhong", "zhi", "zheng",              
                               "zhen", "zhe", "zhao", "zhang", "zhan", "zhai", "zha", "zeng",              
                               "zen", "zei", "ze", "zao", "zang", "zan", "zai", "za", "yun",              
                               "yue", "yuan", "yu", "you", "yong", "yo", "ying", "yin", "yi",              
                               "ye", "yao", "yang", "yan", "ya", "xun", "xue", "xuan", "xu",              
                               "xiu", "xiong", "xing", "xin", "xie", "xiao", "xiang", "xian",              
                               "xia", "xi", "wu", "wo", "weng", "wen", "wei", "wang", "wan",              
                               "wai", "wa", "tuo", "tun", "tui", "tuan", "tu", "tou", "tong",             
                               "ting", "tie", "tiao", "tian", "ti", "teng", "te", "tao",              
                               "tang", "tan", "tai", "ta", "suo", "sun", "sui", "suan", "su",             
                               "sou", "song", "si", "shuo", "shun", "shui", "shuang", "shuan",              
                               "shuai", "shua", "shu", "shou", "shi", "sheng", "shen", "she",              
                               "shao", "shang", "shan", "shai", "sha", "seng", "sen", "se",              
                               "sao", "sang", "san", "sai", "sa", "ruo", "run", "rui", "ruan",              
                               "ru", "rou", "rong", "ri", "reng", "ren", "re", "rao", "rang",              
                               "ran", "qun", "que", "quan", "qu", "qiu", "qiong", "qing",              
                               "qin", "qie", "qiao", "qiang", "qian", "qia", "qi", "pu", "po",              
                               "ping", "pin", "pie", "piao", "pian", "pi", "peng", "pen",              
                               "pei", "pao", "pang", "pan", "pai", "pa", "ou", "o", "nuo",              
                               "nue", "nuan", "nv", "nu", "nong", "niu", "ning", "nin", "nie",              
                               "niao", "niang", "nian", "ni", "neng", "nen", "nei", "ne",              
                               "nao", "nang", "nan", "nai", "na", "mu", "mou", "mo", "miu",              
                               "ming", "min", "mie", "miao", "mian", "mi", "meng", "men",              
                               "mei", "me", "mao", "mang", "man", "mai", "ma", "luo", "lun",              
                               "lue", "luan", "lv", "lu", "lou", "long", "liu", "ling", "lin",              
                               "lie", "liao", "liang", "lian", "lia", "li", "leng", "lei",              
                               "le", "lao", "lang", "lan", "lai", "la", "kuo", "kun", "kui",              
                               "kuang", "kuan", "kuai", "kua", "ku", "kou", "kong", "keng",              
                               "ken", "ke", "kao", "kang", "kan", "kai", "ka", "jun", "jue",              
                               "juan", "ju", "jiu", "jiong", "jing", "jin", "jie", "jiao",              
                               "jiang", "jian", "jia", "ji", "huo", "hun", "hui", "huang",              
                               "huan", "huai", "hua", "hu", "hou", "hong", "heng", "hen",              
                               "hei", "he", "hao", "hang", "han", "hai", "ha", "guo", "gun",              
                               "gui", "guang", "guan", "guai", "gua", "gu", "gou", "gong",              
                               "geng", "gen", "gei", "ge", "gao", "gang", "gan", "gai", "ga",              
                               "fu", "fou", "fo", "feng", "fen", "fei", "fang", "fan", "fa",              
                               "er", "en", "e", "duo", "dun", "dui", "duan", "du", "dou",              
                               "****", "diu", "ding", "die", "diao", "dian", "di", "deng",              
                               "de", "dao", "dang", "dan", "dai", "da", "cuo", "cun", "cui",             
                               "cuan", "cu", "cou", "cong", "ci", "chuo", "chun", "chui",              
                               "chuang", "chuan", "chuai", "chu", "chou", "chong", "chi",              
                               "cheng", "chen", "che", "chao", "chang", "chan", "chai", "cha",              
                               "ceng", "ce", "cao", "cang", "can", "cai", "ca", "bu", "bo",              
                               "bing", "bin", "bie", "biao", "bian", "bi", "beng", "ben",              
                               "bei", "bao", "bang", "ban", "bai", "ba", "ao", "ang", "an",              
                               "ai", "a" };       
      private int[] code = { -10254, -10256, -10260, -10262, -10270, -10274,              
                            -10281, -10296, -10307, -10309, -10315, -10322, -10328, -10329,              
                            -10331, -10519, -10533, -10544, -10587, -10764, -10780, -10790,              
                            -10800, -10815, -10832, -10838, -11014, -11018, -11019, -11020,              
                            -11024, -11038, -11041, -11045, -11052, -11055, -11067, -11077,              
                            -11097, -11303, -11324, -11339, -11340, -11358, -11536, -11589,              
                            -11604, -11781, -11798, -11831, -11847, -11861, -11867, -12039,              
                            -12058, -12067, -12074, -12089, -12099, -12120, -12300, -12320,              
                            -12346, -12359, -12556, -12585, -12594, -12597, -12607, -12802,              
                            -12812, -12829, -12831, -12838, -12849, -12852, -12858, -12860,              
                            -12871, -12875, -12888, -13060, -13063, -13068, -13076, -13091,              
                            -13095, -13096, -13107, -13120, -13138, -13147, -13318, -13326,              
                            -13329, -13340, -13343, -13356, -13359, -13367, -13383, -13387,              
                            -13391, -13395, -13398, -13400, -13404, -13406, -13601, -13611,              
                            -13658, -13831, -13847, -13859, -13870, -13878, -13894, -13896,             
                            -13905, -13906, -13907, -13910, -13914, -13917, -14083, -14087,             
                            -14090, -14092, -14094, -14097, -14099, -14109, -14112, -14122,             
                            -14123, -14125, -14135, -14137, -14140, -14145, -14149, -14151,              
                            -14159, -14170, -14345, -14353, -14355, -14368, -14379, -14384,             
                            -14399, -14407, -14429, -14594, -14630, -14645, -14654, -14663,              
                            -14668, -14670, -14674, -14678, -14857, -14871, -14873, -14882,             
                            -14889, -14894, -14902, -14908, -14914, -14921, -14922, -14926,             
                            -14928, -14929, -14930, -14933, -14937, -14941, -15109, -15110,              
                            -15117, -15119, -15121, -15128, -15139, -15140, -15141, -15143,              
                            -15144, -15149, -15150, -15153, -15158, -15165, -15180, -15183,             
                            -15362, -15363, -15369, -15375, -15377, -15385, -15394, -15408,             
                            -15416, -15419, -15435, -15436, -15448, -15454, -15625, -15631,             
                            -15640, -15652, -15659, -15661, -15667, -15681, -15701, -15707,             
                            -15878, -15889, -15903, -15915, -15920, -15933, -15944, -15958,             
                            -15959, -16155, -16158, -16169, -16171, -16180, -16187, -16202,             
                            -16205, -16212, -16216, -16220, -16393, -16401, -16403, -16407,             
                            -16412, -16419, -16423, -16427, -16429, -16433, -16448, -16452,             
                            -16459, -16465, -16470, -16474, -16647, -16657, -16664, -16689,             
                            -16706, -16708, -16733, -16915, -16942, -16970, -16983, -17185,             
                            -17202, -17417, -17427, -17433, -17454, -17468, -17482, -17487,             
                            -17496, -17676, -17683, -17692, -17697, -17701, -17703, -17721,            
                            -17730, -17733, -17752, -17759, -17922, -17928, -17931, -17947,            
                            -17950, -17961, -17964, -17970, -17988, -17997, -18012, -18181,            
                            -18183, -18184, -18201, -18211, -18220, -18231, -18237, -18239,            
                            -18446, -18447, -18448, -18463, -18478, -18490, -18501, -18518,            
                            -18526, -18696, -18697, -18710, -18722, -18731, -18735, -18741,            
                            -18756, -18763, -18773, -18774, -18783, -18952, -18961, -18977,            
                            -18996, -19003, -19006, -19018, -19023, -19038, -19212, -19218,            
                            -19224, -19227, -19235, -19238, -19242, -19243, -19249, -19261,            
                            -19263, -19270, -19275, -19281, -19288, -19289, -19467, -19479,            
                            -19484, -19500, -19515, -19525, -19531, -19540, -19715, -19725,            
                            -19728, -19739, -19741, -19746, -19751, -19756, -19763, -19774,            
                            -19775, -19784, -19805, -19976, -19982, -19986, -19990, -20002,            
                            -20026, -20032, -20036, -20051, -20230, -20242, -20257, -20265,            
                            -20283, -20292, -20295, -20304, -20317, -20319 };      
      public String getPinyin(String gb2312) {           
          if (null == gb2312 || "".equals(gb2312.trim()))
          {               
              return gb2312;           
          }           
          char[] chars = gb2312.toCharArray();           
          StringBuffer retuBuf = new StringBuffer();          
          for (int i = 0, Len = chars.length; i < Len; i++)
          {               
              retuBuf.append(getPinyin(chars[i])); 
             
          }       
          return retuBuf.toString();       
      }     
      public String getPinyin(char gb2312) {           
          int ascii = getCnAscii(gb2312);           
          if (ascii == 0) {               
              return String.valueOf(gb2312);           
          }
          else
          {               
              String spell = getSpellByAscii(ascii);               
              if (spell == null)
              {                  
                  return String.valueOf(gb2312);               
              }
              else
              {                   
                  return spell;              
              }
          }       
      }      
      private int getCnAscii(char cn) {         
          byte[] bytes = null;           
          try{              
               bytes = (String.valueOf(cn)).getBytes("GB2312");         
          } catch (Exception e) {e.printStackTrace();}   
          if (bytes == null || bytes.length > 2 || bytes.length <= 0)
          {               
               return 0;          
          }         
          if (bytes.length == 1)
          {              
              return bytes[0];           
          }
          else
          {             
              int hightByte = 256 + bytes[0];              
              int lowByte = 256 + bytes[1];             
              int ascii = (256 * hightByte + lowByte) - 256 * 256;          
              return ascii;           
          }       
      }    

       private String getSpellByAscii(int ascii) {           
           if (ascii > 0 && ascii < 160)
           { // 单字符              
                 return String.valueOf((char) ascii);         
           }          
           if (ascii < -20319 || ascii > -10247) { // 不知道的字符             
                 return "?";            }          
           int ind;          
           for (ind = 0; ind < code.length; ind++) {       
               if (ascii >= code[ind])
               {            
                    break;              
               }           
           }        
           return name[ind];      
       }  
  }
分享到:
评论

相关推荐

    解决Sqlite中文排序问题(网页)

    总结来说,解决SQLite中文排序问题的关键在于理解Unicode排序算法,并在SQLite中创建自定义的Collation。通过编写UDF将中文转换为可比较的形式,可以实现符合预期的中文排序。这个过程可能涉及编码工作,但能确保在...

    SQLite小蝴蝶安装包

    这个“SQLite小蝴蝶安装包”很可能是用于在计算机上安装SQLite数据库管理工具的程序,比如SQLite Expert Personal,这是一款流行且功能丰富的SQLite数据库管理与开发工具。 SQLite数据库系统的设计目标是提供一种...

    sqlite3 for delphi 解决中文乱码问题

    在使用SQLite3数据库引擎与Delphi集成开发过程中,经常遇到的一个挑战是中文字符显示为乱码。"sqlite3 for delphi 解决中文乱码问题"这个主题,正是针对这一问题提供了解决方案。这里我们将详细探讨SQLite3在Delphi...

    易语言模块Sqlite表管理.rar

    易语言模块Sqlite表管理.rar 易语言模块Sqlite表管理.rar 易语言模块Sqlite表管理.rar 易语言模块Sqlite表管理.rar 易语言模块Sqlite表管理.rar 易语言模块Sqlite表管理.rar

    SQLite 中文教程 完整版

    《SQLite 中文教程》有助于初学者了解 SQLite 数据库引擎相关的基础知识和先进理念。主要介绍了本教程提供了所有重要的内置的 SQLite 函数的参考手册,同时也列出了SQLite 数据库网站和书籍。 本教程帮助您了解什么...

    sqlite中英文帮助

    这个压缩包文件包含的"SQLite中英文帮助"很可能是SQLite的官方文档,包括了SQLite的API参考、SQL语言指南以及错误代码等详细信息。在本文中,我们将深入探讨SQLite的一些关键知识点。 首先,SQLite支持SQL标准,...

    调用sqlite开源数据的小程序,能够往数据库中写入数据

    这个小程序展示了如何调用SQLite来实现数据的写入功能,对于初学者来说,了解和掌握SQLite的基本操作是非常有益的。 SQLite的核心特性包括: 1. **轻量级**:SQLite不需要单独的服务器进程,它是一个自包含的库,...

    数据库sqlite 小型数据库

    SQLite是一款轻量级的、开源的、自包含的数据库引擎,特别适合于嵌入式应用,无需单独的服务器进程,可以被直接集成到各种应用程序中。它的设计目标是提供一个可移植的、可靠的、高性能的数据库解决方案,尤其适用于...

    sqlite 支持中文模糊查询

    在描述中提到的问题是关于SQLite对中文模糊查询的支持。 在早期的一些SQLite版本中,由于编码或字符集处理的问题,可能会遇到在执行LIKE查询时,中文字符无法正确匹配的情况。LIKE操作符在SQL中用于执行模糊匹配,...

    中文sqlite(中文路径,中文文件名,中文表名,中文列名,中文内容)

    该项目为unicode编码格式,一个简单的操作sqlite的Demo,支持简单的增删查改,支持中文路径,中文文件名,中文表名,中文列名,中文内容。可以在此基础上添加自己想要的各种操作 项目中用到的sqlite3.dll,sqlite3....

    Inside SQLite(SQLite技术内幕) 原版+个人翻译版

    另一方面,“inside sqlite.pdf”很可能是原版英文书籍,它通常会涵盖更广泛的SQLite技术内容,例如它的源代码组织结构、编译和链接选项,以及与应用程序的集成方式。书中可能还会涉及错误处理、安全性、性能调优和...

    汉字转拼音 sqlite

    换点积分好下载点儿东西,谢谢大家!是从mdb 转过来的。东西不错,比较全。大家一起用用吧!

    Sqlite3中文路径解决

    针对这个问题,我们可以采取一些策略来确保SQLite3在C++环境中正确地处理中文路径。 首先,我们需要理解SQLite3的基础。SQLite3是一个轻量级的、自包含的、无服务器的SQL数据库引擎,广泛应用于各种嵌入式系统和...

    sqlite汉字拼音对照表

    sqlite汉字拼音对照表,有 常用汉字表6986个 和 gbk汉字库21000个 两张表,带汉字的gbk编码

    SQLite 3.0 小型数据库

    SQLite是一个软件库,用于实现自包含...SQLite直接读写原始的磁盘文件,一个拥有多个表、索引、触发器和视图的完整SQL数据库就包含在一个独立的磁盘文件中。数据库文件的格式是跨平台的,你可以在32位和64位系统之间、

    Sqlite3修复小工具

    sqlitefix.exe sqlite3DBFile 界面使用,可以拖放损坏的文件到选择框中 命令行使用为同文件名修复 界面使用会生成.New 的数据库文件 修复完毕的数据库文件可能会比原数据库文件小,因为重建时收缩所知! 因为...

    SQLite 安装包 sqlite3 及sqlite数据库jdbc jar包

    SQLite是一种轻量级的、开源的关系型数据库管理系统,它不需要单独的服务器进程,可以直接嵌入到应用程序中使用,因此在移动设备和小型应用系统中非常流行。SQLite3是SQLite的第三个主要版本,提供了更高的性能、...

    sqlite小型数据库

    SQLite是一款轻量级的、开源的关系型数据库管理系统,它无需单独的服务器进程,可以直接嵌入到各类应用程序中,尤其适合于中小型开发。SQLite以其小巧、高效、可靠的特点,被广泛应用于移动设备、嵌入式系统以及桌面...

    sqlite(中文API)

    在“sqlite(中文).chm”文件中,通常包含了SQLite中文API的详细文档,包括函数介绍、参数说明、示例代码以及常见问题解答。这个帮助文件是学习和参考SQLite API的重要资源,它覆盖了如`sqlite3_open()`用于打开...

    sqliteodbc驱动sqlite3

    - **环境变量设置**:在某些系统中可能还需要配置ODBC数据源管理器或添加系统环境变量,确保SQLiteODBC驱动能够被正确识别。 ##### 3. 测试连接 - **创建数据源**:通过ODBC数据源管理器创建一个新的SQLite数据源...

Global site tag (gtag.js) - Google Analytics