在做项目的时候,输入客户的名字,为了方便索引汉字字符串的拼音首字母,作助记码,于是到网上找了一下,还好,有个单个汉字的处理!为了答谢该网友!为了以后的网友,我做了汉字字符串的处理!
还请各位网友指教[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[];
long ChineseStr_int;
string CharStr,ChinaStr="";
for (int i=0;i<=ChineseStr.Length-;i++)
{
CharStr=ChineseStr.Substring(i,).ToString();
ZW=System.Text.Encoding.Default.GetBytes(CharStr);
// 得到汉字符的字节数组
if(ZW.Length==)
{
int i = (short)(ZW[0]);
int i = (short)(ZW[]);
ChineseStr_int=i*6+i;
//table of the constant list
// 'A'; //7..
// 'B'; //..760
// 'C'; //76..67
// 'D'; //68..68
// 'E'; //686..7009
// 'F'; //700..796
// 'G'; //797..76
// 'H'; //76..88
// 'J'; //89..906
// 'K'; //906..9
// 'L'; //9..989
// 'M'; //9896..070
// 'N'; //07..06
// 'O'; //06..06
// 'P'; //06..090
// 'Q'; //0906..86
// 'R'; //87..
// 'S'; //6..7
// 'T'; //8..697
//没有U,V
// 'W'; //698..979
// 'X'; //980..60
// 'Y'; //689..80
// 'Z'; //8..89
if ((ChineseStr_int>=7) && (ChineseStr_int<=))
{
ChinaStr= "A";
}
else if ((ChineseStr_int>=) && (ChineseStr_int<=760))
{
ChinaStr= "B";
}
else if ((ChineseStr_int>=76) && (ChineseStr_int<=67))
{
ChinaStr= "C";
}
else if ((ChineseStr_int>=68) && (ChineseStr_int<=68))
{
ChinaStr= "D";
}
else if ((ChineseStr_int>=686) && (ChineseStr_int<=7009))
{
ChinaStr= "E";
}
else if ((ChineseStr_int>=700) && (ChineseStr_int<=796))
{
ChinaStr= "F";
}
else if ((ChineseStr_int>=797) && (ChineseStr_int<=76))
{
ChinaStr= "G";
}
else if ((ChineseStr_int>=76) && (ChineseStr_int<=88))
{
ChinaStr= "H";
}
else if ((ChineseStr_int>=89) && (ChineseStr_int<=906))
{
ChinaStr= "J";
}
else if ((ChineseStr_int>=906) && (ChineseStr_int<=9))
{
ChinaStr= "K";
}
else if ((ChineseStr_int>=9) && (ChineseStr_int<=989))
{
ChinaStr= "L";
}
else if ((ChineseStr_int>=9896) && (ChineseStr_int<=070))
{
ChinaStr= "M";
}
else if ((ChineseStr_int>=07) && (ChineseStr_int<=06))
{
ChinaStr= "N";
}
else if ((ChineseStr_int>=06) && (ChineseStr_int<=06))
{
ChinaStr= "O";
}
else if ((ChineseStr_int>=06) && (ChineseStr_int<=090))
{
ChinaStr= "P";
}
else if ((ChineseStr_int>=0906) && (ChineseStr_int<=86))
{
ChinaStr= "Q";
}
else if ((ChineseStr_int>=87) && (ChineseStr_int<=))
{
ChinaStr= "R";
}
else if ((ChineseStr_int>=6) && (ChineseStr_int<=7))
{
ChinaStr= "S";
}
else if ((ChineseStr_int>=8) && (ChineseStr_int<=697))
{
ChinaStr= "T";
}
else if ((ChineseStr_int>=698) && (ChineseStr_int<=979))
{
ChinaStr= "W";
}
else if ((ChineseStr_int>=980) && (ChineseStr_int<=60))
{
ChinaStr= "X";
}
else if ((ChineseStr_int>=689) && (ChineseStr_int<=80))
{
ChinaStr= "Y";
}
else if ((ChineseStr_int>=8) && (ChineseStr_int<=89))
{
ChinaStr= "Z";
}
}
else
{
Capstr=ChineseStr;
break;
}
Capstr=Capstr+ChinaStr;
}
return Capstr;
}
}
}









