C# 汉字转拼音(支持GB2312字符集中所有汉字)

C# 汉字转拼音(支持GB2312字符集中所有汉字)C# 汉字转拼音(支持GB2312字符集中所有汉字)
GB2312标准共收录6763个汉字,其中一级汉字3755个,二级汉字3008个。
 
分区表示 
 GB 2312中对所收汉字进行了“分区”处理,每区含有94个汉字/符号。这种表示方式也称为区位码。
 )-09区为特殊符号。
 )-55区为一级汉字,按拼音排序。 
 )-87区为二级汉字,按部首/笔画排序。
 )-15区及88-94区则未有编码。

  也就是说二级汉字与拼音不存在联系。这样网上大部分汉字转拼音类只能正确获取部分汉字的拼音(一级汉字).只有小数的3000多一点汉字.  而二级汉字根本查询不到,比如“蜻蜓”,比如"闰",虽然网上补上了二级汉字中"深圳"的圳,但与二级汉字的的总数相比,显得还是远远不够的。

因此据于上面的问题就对现有网上存在的方法进行了扩展,使其能获取GB2312-80编码规则中的所有中文汉字.

  功能描述:

  1.汉字字符串转换为全拼表示

  2.汉字字符串转换为全拼音的首字母表示.比如:"生活的七色板"返回的是"SHDQSB"

相比现有网上绝大部分方法做的性能改进:

  性能及改进:
    1.使用StringBuilder连接要解析的字符串中的各个拼音.这个方法大量的字符串性能改善非常明显。      
  2.对一级字符串(日常使用最普遍的汉字)采用分块查找.加快查找速度。
  3.支持一二级所有汉字(也就是支持所有GB2312字符集中汉字)。

   缺点:不能区分多音字,只完全支持GB2312-80汉字库,如果是多音字,只能得到最后一个列表中的拼音。

  补充:如果想支持多音字,建议用词库资源库的方式进行查找编程。如果有时间,我也会用这个词库资源库方式再作一个汉字转拼音的类库,以尽量支持汉字多音字及标号拼音。敬请关注。

  下面是当前改进的汉字转拼音类:

C# 汉字转拼音(支持GB2312字符集中所有汉字)C# 汉字转拼音(支持GB2312字符集中所有汉字)
, -, -, -, -, -, -, -, -, 
, -, -, -, -, -, -, -, -,
, -, -, -, -, -, -, -, -, 
, -, -, -, -, -, -, -, -, 
, -, -, -, -, -, -, -, -, 
, -, -, -, -, -, -, -, -, 
, -, -, -, -, -, -, -, -,
, -, -, -, -, -, -, -, -, 
, -, -, -, -, -, -, -, -,
, -, -, -, -, -, -, -, -,
, -, -, -, -, -, -, -, -, 
, -, -, -, -, -, -, -, -, 
, -, -, -, -, -, -, -, -,
, -, -, -, -, -, -, -, -, 
, -, -, -, -, -, -, -, -, 
, -, -, -, -, -, -, -, -, 
, -, -, -, -, -, -, -, -, 
, -, -, -, -, -, -, -, -,
, -, -, -, -, -, -, -, -, 
, -, -, -, -, -, -, -, -, 
, -, -, -, -, -, -, -, -,
, -, -, -, -, -, -, -, -, 
, -, -, -, -, -, -, -, -, 
, -, -, -, -, -, -, -, -, 
, -, -, -, -, -, -, -, -,
, -, -, -, -, -, -, -, -, 
, -, -, -, -, -, -, -, -,
, -, -, -, -, -, -, -, -,
, -, -, -, -, -, -, -, -, 
, -, -, -, -, -, -, -, -, 
, -, -, -, -, -, -, -, -, 
, -, -, -, -, -, -, -, -,
, -, -, -, -, -, -, -, -, 
, -, -, -, -, -, -, -, -, 
, -, -, -, -, -, -, -, -, 
, -, -, -, -, -, -, -, -,
, -, -, -, -, -, -, -, -,
, -, -, -, -, -, -, -, -,
, -, -, -, -, -, -, -, -, 
, -, -, -, -, -, -, -, -,
, -, -, -, -, -, -, -, -,
             -, -, -, -, -, -, -, -, -,
 
             -, -, -, -, -, -, -, -, -, 
 
             -, -, -, -, -, -, -, -, - 
 
         };
 
          
          { 
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
               
                        };
 
                              {
                          ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,             ,         };
 
                        {                         
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       };
                            ;
          ;
          ;
                              
                        {
                            , ); 
                              
                        }
 
                        {
               
              ); 
               
              ; i < chs.Length; i++) 
              { 
                  sb.Append(GetFirst(chs[i]));
              } 
              
                        }
         
                        {
                
                
                
                              ] *  + (Int16)arr[] - ;
 
                && chr < )                
                             {
                                }
                             {
                   ; aPos >= ; aPos--)
                  {
                      ;
                                             {
                             ; i >= aboutPos; i--)
                          {
                                                            {
                                                                 }
                          }
                                                }
                  }
              }
                             {
                                                      {
                                        }
              }
               
                                             }
 
                        {
                            
              ); 
                            
              ; j < chs.Length; j++) 
              { 
                  sb.Append(Get(chs[j])); 
              } 
              
                        }
     }
 }
上一篇:23种设计模式之抽象工厂(Abstract Factory)


下一篇:系统集成之用户统一登录( LDAP + wso2 Identity Server)