在做項目的時候,輸入客戶的名字,為了方便索引漢字字符串的拼音首字母,作助記碼,于是到網上找了一下,還好,有個單個漢字的處理!為了答謝該網友!為了以后的網友,我做了漢字字符串的處理! 還請各位網友指教[email protected]! 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