最近做一个项目,需要调用分类名称的首字母做索引。。但如果每次添加分类都手动输入首字母又太麻烦,上网翻了下资料,只发现了asp的代码,没有asp.net的。呵呵。就自己随手改了下,丢出来给新手用。
声明:没什么技术含量,高手免入。哈哈。
//获取输入字符的ascii编码
public int asc(char mm)
{
byte[] aa = System.Text.Encoding.Default.GetBytes(mm.ToString());
int pp = 0;
if (aa.Length == 1)
{
pp =(int)aa[0];
}
else
{
for (int i = 0; i < aa.Length; i+=2)
{
pp = (int)aa[i];
pp = pp * 256 + aa[i + 1] - 65536;
}
}
return pp;
}
//获取汉字或英文的首字母
public char FirstChar(char InputChar)
{