麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

漢字助記碼,你會了嗎?

2019-11-14 16:40:33
字體:
供稿:網(wǎng)友

     漢字助記碼,你會了嗎?

       在編程中,我們經(jīng)常會遇到漢字助記碼的問題,筆者曾經(jīng)為此多次發(fā)愁,現(xiàn)總結(jié)前輩的好東西,記錄于此,希望能幫助到您,方法有多種,在此比較幾種方案,簡單剖析一下。

      首先說明,什么是漢字助記碼?所謂的漢字助記碼就是一個漢字的拼音的首字母,如:張的漢字助記碼為Z,湖北中醫(yī)藥大學(xué)的助記碼為HBZYYDX。下面通過程序用三種方法實現(xiàn):

     方法一:表獲取方法; 

     表內(nèi)容大致說明:      

      實現(xiàn)核心代碼——SQL標(biāo)量值函數(shù):

 1 ------------------------------------------------ 2 --作者:zhangbc 3 --時間:2014-05-05 4 --功能:獲取漢字拼音首字母 5 ------------------------------------------------ 6 ALTER function [dbo].[fun_getMnemonic](@str nvarchar(4000))  7 returns nvarchar(4000)  8 as  9 begin10 declare @zjm varchar(100),@tmp_char varchar(2),@tmp_zjm varchar(2),  @i int,@length int11      set @zjm =''12      set @length = len(@str)13      set @i = 114      while @i<=@length 15      begin16          set @tmp_char = substring(@str,@i,1)17          select @tmp_zjm =zjm from hz_zjm where hanzi=@tmp_char18          if @@rowcount=1 19          set @zjm = @zjm +Rtrim(@tmp_zjm)20          set @i = @i + 1 21      end   22     return (@zjm)23 end 
View Code

     方法二:存儲過程獲取;

     實現(xiàn)核心代碼——SQL存儲過程:

 1 -- ============================================= 2 -- Author:    zhangbc 3 -- Create date: 2014-05-03 4 -- Description:    獲取漢字拼音首字母 5 -- ============================================= 6 ALTER PROCEDURE [dbo].[getMnemonic]  7       @str varchar(4000) 8 AS 9 --     return char(4000)10 BEGIN11     declare @Word nchar(1),@PY nvarchar(4000) 12     set @PY='' 13     while len(@str)>0 14     begin 15     set @word=left(@str,1) 16     --如果非漢字字符,返回原字符 17     set @PY=@PY+(case when unicode(@word) between 19968 and 19968+20901 18     then (select top 1 PY from ( 19     select 'A' as PY,N'' as word 20     union all select 'B',N'簿' 21     union all select 'C',N'' 22     union all select 'D',N'' 23     union all select 'E',N'' 24     union all select 'F',N'' 25     union all select 'G',N'' 26     union all select 'H',N'' 27     union all select 'J',N'' 28     union all select 'K',N'' 29     union all select 'L',N'' 30     union all select 'M',N'' 31     union all select 'N',N'' 32     union all select 'O',N'' 33     union all select 'P',N'' 34     union all select 'Q',N'' 35     union all select 'R',N'' 36     union all select 'S',N'' 37     union all select 'T',N'' 38     union all select 'W',N'' 39     union all select 'X',N'' 40     union all select 'Y',N'' 41     union all select 'Z',N'' 42     ) T 43     where word>=@word collate Chinese_PRC_CS_AS_KS_WS 44     order by PY ASC) else @word end) 45     set @str=right(@str,len(@str)-1) 46     end 47     select @PY 48 END
View Code

     方法三:標(biāo)量值獲?。ㄋ惴ê头椒ǘ粯樱瑢崿F(xiàn)方式不同):

     代碼如下:

 1 ------------------------------------------------ 2 --作者:zhangbc 3 --時間:2014-03-19 4 --功能:獲取漢字拼音首字母 5 ------------------------------------------------ 6 ALTER function [dbo].[fun_getZjm](@str nvarchar(4000))  7 returns nvarchar(4000)  8 as  9 begin 10 declare @word nchar(1),@PY nvarchar(4000) 11 set @PY='' 12 while len(@str)>0 13 begin 14 set @word=left(@str,1) 15 --如果非漢字字符,返回原字符 16 set @PY=@PY+(case when unicode(@word) between 19968 and 19968+20901 17 then (select top 1 PY from ( 18 select 'A' as PY,N'' as word 19 union all select 'B',N'簿' 20 union all select 'C',N'' 21 union all select 'D',N'' 22 union all select 'E',N'' 23 union all select 'F',N'' 24 union all select 'G',N'' 25 union all select 'H',N'' 26 union all select 'J',N'' 27 union all select 'K',N'' 28 union all select 'L',N'' 29 union all select 'M',N'' 30 union all select 'N',N'' 31 union all select 'O',N'' 32 union all select 'P',N'' 33 union all select 'Q',N'' 34 union all select 'R',N'' 35 union all select 'S',N'' 36 union all select 'T',N'' 37 union all select 'W',N'' 38 union all select 'X',N'' 39 union all select 'Y',N'' 40 union all select 'Z',N'' 41 ) T 42 where word>=@word collate Chinese_PRC_CS_AS_KS_WS 43 order by PY ASC) else @word end) 44 set @str=right(@str,len(@str)-1) 45 end 46 return @PY 47 end 
View Code

     方法四:字符編碼法;

     核心代碼如下:

 1  public class getMnemonic 2     { 3         public getMnemonic() 4         { 5  6         } 7         /// <summary> 8         /// 字符編碼的獲取 9         /// </summary>10         /// <param name="cnChar">字符</param>11         /// <returns>字符編碼</returns>12         private static string getSpell(string cnChar)13         {14             byte[] arrCN = Encoding.Default.GetBytes(cnChar);15             if (arrCN.Length > 1)16             {17                 int area = (short)arrCN[0];18                 int pos = (short)arrCN[1];19                 int code = (area << 8) + pos;20                 int[] areacode = { 45217, 45253, 45761, 46318, 46826, 47010, 47297, 47614, 21                                      48119, 48119, 49062, 49324, 49896,50371, 50614, 50622,22                                      50906, 51387, 51446, 52218, 52698, 52698, 52698, 52980, 53689, 54481 };23                 for (int i = 0; i < 26; i++)24                 {25                     int max = 55290;26                     if (i != 25)27                         max = areacode[i + 1];28                     if (areacode[i] <= code && code < max)29                         return Encoding.Default.GetString(new byte[] { (byte)(65 + i)});30                 }31                 return "*";32             }33             else return cnChar;34         }35         /// <summary>36         /// 字符編碼獲取助記碼37         /// </summary>38         /// <param name="str">漢字</param>39         /// <returns>助記碼</returns>40         public string getChsSpell(string str)41         {42             string myStr = "";43             for (int i = 0; i < str.Length; i++)44             {45                 myStr += getSpell(str.Substring(i, 1));46             }47             return myStr;48         }49     }
View Code

    測試結(jié)果如下:

     圖1-1

  圖1-2

圖1-3

圖1-4

     小結(jié):

           通過測試結(jié)果來看,字符編碼(方法四)還是有點不完美,其實通過表獲取的方法(方法一)也存在不足,漢字存儲太少。

          這次測試的一個意外收獲就是char()與varchar()的區(qū)別,請看:

         

            還望知情者給予合理的解釋,不甚感激!如果能給你帶來幫助,請贊一個,你的用心閱讀是我寫博的不竭動力!

            贈送源碼一份,供您研究:http://files.VEVb.com/zhangbc/MnemonicOfWords.rar

            PS:如有不足之處,歡迎指點與切磋,您的光臨是我的榮幸,聯(lián)系方式QQ649414754 


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 日本一区视频在线观看 | 精品一区视频 | 国产免费观看a大片的网站 欧美成人一级 | 欧美黄色看 | porno video hd 365hd | 国产一区精品在线观看 | 亚洲免费网站 | 国产亚洲美女精品久久久2020 | 中文字幕在线观看www | 国内精品久久久久影院不卡 | 黄色一级毛片免费看 | 国产一区毛片 | 在线看毛片的网站 | 成人av一区二区免费播放 | 毛片免费在线 | 中文字幕在线免费观看电影 | a级毛片免费观看在线播放 日本aaa一级片 | h视频免费看 | 久久人人97超碰国产公开结果 | 宅男噜噜噜66国产免费观看 | 国产精品久久久乱弄 | 亚洲午夜在线 | 精品中文字幕在线观看 | 午夜精品一区二区三区免费 | 91精品国产91久久久久久吃药 | 黄色网址进入 | 免费黄色小网站 | 黑人一区二区 | 久久久国产精品免费观看 | 国产91久久精品一区二区 | 污污黄 | 日韩视频区 | 9191久久久久视频 | 成人午夜免费在线视频 | 国产成人在线视频播放 | 夜间福利网站 | av不卡毛片| 视频一区二区三区在线播放 | 日本娇小videos高潮 | 国产成人强伦免费视频网站 | 狠狠撸电影 |