欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
使用拼音搜索中文
    最近忙一個(gè)地址簿的小項目,需要實(shí)現類(lèi)似 outlook 的功能,即通過(guò)聯(lián)系人姓氏的拼音的聲母找到相關(guān)的聯(lián)系人,比如  按 Z 那么找出所有姓張的聯(lián)系人,其他以拼音 Z 開(kāi)頭也會(huì )找出來(lái),比如姓趙、鄭 ......,當然 Zidane(齊達內)也會(huì )被找出來(lái)。
    
    我有 java 實(shí)現的代碼,如下:
 public static char getInitial(String str)
 {
  byte[] bs;
  try
  {
   bs=str.getBytes("gb2312");
  }
  catch(java.io.UnsupportedEncodingException e)
  {
   return ‘*‘;
  }
  
  if(bs.length==0)
   return ‘*‘;
   
  switch(bs[0])
  {
   case (byte)‘a(chǎn)‘: case (byte)‘A‘: return ‘a(chǎn)‘;
   case (byte)‘b‘: case (byte)‘B‘: return ‘b‘;
   case (byte)‘c‘: case (byte)‘C‘: return ‘c‘;
   case (byte)‘d‘: case (byte)‘D‘: return ‘d‘;
   case (byte)‘e‘: case (byte)‘E‘: return ‘e‘;
   case (byte)‘f‘: case (byte)‘F‘: return ‘f‘;
   case (byte)‘g‘: case (byte)‘G‘: return ‘g‘;
   case (byte)‘h‘: case (byte)‘H‘: return ‘h‘;
   case (byte)‘i‘: case (byte)‘I‘: return ‘i‘;
   case (byte)‘j‘: case (byte)‘J‘: return ‘j‘;
   case (byte)‘k‘: case (byte)‘K‘: return ‘k‘;
   case (byte)‘l‘: case (byte)‘L‘: return ‘l‘;
   case (byte)‘m‘: case (byte)‘M‘: return ‘m‘;
   case (byte)‘n‘: case (byte)‘N‘: return ‘n‘;
   case (byte)‘o‘: case (byte)‘O‘: return ‘o‘;
   case (byte)‘p‘: case (byte)‘P‘: return ‘p‘;
   case (byte)‘q‘: case (byte)‘Q‘: return ‘q‘;
   case (byte)‘r‘: case (byte)‘R‘: return ‘r‘;
   case (byte)‘s‘: case (byte)‘S‘: return ‘s‘;
   case (byte)‘t‘: case (byte)‘T‘: return ‘t‘;
   case (byte)‘u‘: case (byte)‘U‘: return ‘u‘;
   case (byte)‘v‘: case (byte)‘V‘: return ‘v‘;
   case (byte)‘w‘: case (byte)‘W‘: return ‘w‘;
   case (byte)‘x‘: case (byte)‘X‘: return ‘x‘;
   case (byte)‘y‘: case (byte)‘Y‘: return ‘y‘;
   case (byte)‘z‘: case (byte)‘Z‘: return ‘z‘;
   default:
   if(bs.length>=2) //長(cháng)度>=2就有可能是中文
   {
    int b1=bs[0]&0xff;
    int b2=bs[1]&0xff;
    int value=(b1<<8)|b2;
    System.out.println(value);
    if( value>=0xb0a1 && value<=0xb0c4) return ‘a(chǎn)‘;
    if( value>=0xb0c5 && value<=0xb2c0) return ‘b‘;
    if( value>=0xb2c1 && value<=0xb4ed) return ‘c‘;
    if( value>=0xb4ee && value<=0xb6e9) return ‘d‘;
    if( value>=0xb6ea && value<=0xb7a1) return ‘e‘;
    if( value>=0xb7a2 && value<=0xb8c0) return ‘f‘;
    if( value>=0xb8c1 && value<=0xb9fd) return ‘g‘;
    if( value>=0xb9fe && value<=0xbbf6) return ‘h‘;
    if( value>=0xbbf7 && value<=0xbfa5) return ‘j‘;
    if( value>=0xbfa6 && value<=0xc0ab) return ‘k‘;
    if( value>=0xc0ac && value<=0xc2e7) return ‘l‘;
    if( value>=0xc2e8 && value<=0xc4c2) return ‘m‘;
    if( value>=0xc4c3 && value<=0xc5b5) return ‘n‘;
    if( value>=0xc5b6 && value<=0xc5bd) return ‘o‘;
    if( value>=0xc5be && value<=0xc6d9) return ‘p‘;
    if( value>=0xc6da && value<=0xc8ba) return ‘q‘;
    if( value>=0xc8bb && value<=0xc8f5) return ‘r‘;
    if( value>=0xc8f6 && value<=0xcbf9) return ‘s‘;
    if( value>=0xcbfa && value<=0xcdd9) return ‘t‘;
    if( value>=0xcdda && value<=0xcef3) return ‘w‘;
    if( value>=0xcef4 && value<=0xd188) return ‘x‘;
    if( value>=0xd1b9 && value<=0xd4d0) return ‘y‘;
    if( value>=0xd4d1 && value<=0xd7f9) return ‘z‘;
   }
  }
  
  return ‘*‘;
 }    

    代碼其實(shí)很簡(jiǎn)單,要了解為什么要這么寫(xiě),則需要了解一下 GB2312 編碼,我覺(jué)得HP的官方網(wǎng)站的資料還不錯,簡(jiǎn)單明了。網(wǎng)址是這里。里面有一段是這樣的:

    國標 GB2312 基于 1980 年發(fā)布的《信息交換用漢字編碼字符集基本集》,是中文信息處理的中國國家標準,是強制執行的中文編碼。
    國標碼共收錄 6763 個(gè)簡(jiǎn)體漢字、682 個(gè)符號,其中漢字部分:一級字 3755 個(gè),以拼音排序,二級字 3008 個(gè),以偏旁部首排序。該標準的制定和應用為規范、推動(dòng)中文信息化進(jìn)程起了很大作用。該標準用雙字節表示一個(gè)漢字:高字節 A1-F7(其中字符區 A1-F9,漢字區 B0-F7)低字節 A1-FE。

    上面的文字已經(jīng)說(shuō)得很清楚,最常用的 3755 個(gè)漢字是用拼音排序的,所以才有可能比較方便的實(shí)現用拼音找到漢字。同樣也說(shuō)明了,有一些少見(jiàn)的姓通過(guò)上面的代碼是找不出來(lái)的,比如臺灣有個(gè)叫庹中康的主持人。

    不過(guò)在我那個(gè)小項目里,小到覺(jué)得編譯 java 都多余,我希望用 javascript 就實(shí)現同上 java 實(shí)現的功能。我再次求助google,找到了 http://www.blueidea.com/user/qswh/qswhGB2312.js。網(wǎng)上能人輩出啊。范例可以看看 http://www.blueidea.com/user/qswh/GB2312.html。

    這個(gè)腳本用來(lái)解析出漢字的拼音。我加了一個(gè)方法以滿(mǎn)足我的需要,代碼如下:
function getInitial(str) {
 if (str == null || /^\s*$/.test(str)) return null;
 try {
  var code = str.charCodeAt(0); //charCodeAt方法需要ie5.5 以上才支持
  if (code >= 48 && code <= 57) // 如果是數字,就返回
   return str.charAt(0);
  else if (code <= 127) {
   return str.charAt(0).toUpperCase();
  }
  else {
   var py = getSpell(str);  //getSpell()得到字符串的拼音
   return (py)?py.substring(0,1).toUpperCase():null;
  }
 }
 catch (e) {
  return null;
 }
}

    qswhGB2312.js 文件中將常用的3755個(gè)漢字組成一個(gè)字符串賦予一個(gè)變量。因為包含漢字,所以如果 jsp 或者 template 頁(yè)面使用的是非gb2312的編碼,比如UTF-8,那么就需要在<script>中加一個(gè) charset=gb2312,比如:
    <script language="javascript" src="qswhGB2312.js" charset="gb2312"></script>

    因為項目要求支持中簡(jiǎn)繁,我想知道Big5碼是否也有類(lèi)似的拼音的設計,看了《由 堃(方方土) 探討 Big5e 編碼》,知道了大概是不行的,同時(shí)感覺(jué)大陸在計算機語(yǔ)言編碼設計方面比臺灣還是要大氣得多。
    去年看過(guò)一些文章不少人攻擊漢字拉丁化和簡(jiǎn)化字等等改革,有些還是有道理,不過(guò)說(shuō)句公道話(huà),拼音對于計算機的漢語(yǔ)錄入還是貢獻巨大,我沒(méi)有歧視五筆的意思,不過(guò)我總是努力勸說(shuō)身邊的人嘗試用拼音輸入法。
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
用JAVA實(shí)現漢字轉拼音縮寫(xiě)
mysql 中取得漢字字段的各漢字首字母
單片機程序優(yōu)化經(jīng)驗
獲得一條指令(opcode and opdata)長(cháng)度的函數(轉)
用Java實(shí)現JVM第五章《指令集和解釋器》
MySQL拼音首字母查詢(xún)
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久