在做项目的时候,输入客户的名字,为了方便索引汉字字符串的拼音首字母,作助记码,于是到网上找了一下,还好,有个单个汉字的处理!为了答谢该网友!为了以后的网友,我做了汉字字符串的处理! 还请各位网友指教shixiang9076@sina.com! using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data;
namespace WinMarket { /// <summary> /// Classfun 的摘要说明。 /// </summary> public class Classfun { private string Capstr;
public Classfun() { // // TODO: 在此处添加构造函数逻辑 // } public string ChineseCap(string ChineseStr) {
byte[] ZW = new byte[2]; long ChineseStr_int; string CharStr,ChinaStr=""; for (int i=0;i<=ChineseStr.Length-1;i++) { CharStr=ChineseStr.Substring(i,1).ToString(); ZW=System.Text.Encoding.Default.GetBytes(CharStr); // 得到汉字符的字节数组 if(ZW.Length==2) { int i1 = (short)(ZW[0]); int i2 = (short)(ZW[1]); ChineseStr_int=i1*256+i2; //table of the constant list // 'A'; //45217..45252 // 'B'; //45253..45760 // 'C'; //45761..46317 // 'D'; //46318..46825 // 'E'; //46826..47009 // 'F'; //47010..47296 // 'G'; //47297..47613