• 得到中文字符串首拼


    public static string GetFirstLetter(string str)
    {
    char t1;
    string val="";
    for (int i=0;i<str.Trim().Length;i++)
    {
    t1=Convert.ToChar(str.Trim().Substring(i,1));
    if (Ascii(t1)>=Ascii('!') && Ascii(t1)<=Ascii('~'))
    val+=t1;
    else if (Ascii(t1)>=Ascii('啊') && Ascii(t1)<Ascii('芭'))
    val+="A";
    else if (Ascii(t1)>=Ascii('芭') && Ascii(t1)<Ascii('擦'))
    val+="B";
    else if (Ascii(t1)>=Ascii('擦') && Ascii(t1)<Ascii('搭'))
    val+="C";
    else if (Ascii(t1)>=Ascii('搭') && Ascii(t1)<Ascii('蛾'))
    val+="D";
    else if (Ascii(t1)>=Ascii('蛾') && Ascii(t1)<Ascii('发'))
    val+="E";
    else if (Ascii(t1)>=Ascii('发') && Ascii(t1)<Ascii('噶'))
    val+="F";
    else if (Ascii(t1)>=Ascii('噶') && Ascii(t1)<Ascii('哈'))
    val+="G";
    else if (Ascii(t1)>=Ascii('哈') && Ascii(t1)<Ascii('击'))
    val+="H";
    else if (Ascii(t1)>=Ascii('击') && Ascii(t1)<Ascii('喀'))
    val+="J";
    else if (Ascii(t1)>=Ascii('喀') && Ascii(t1)<Ascii('拉'))
    val+="K";
    else if (Ascii(t1)>=Ascii('拉') && Ascii(t1)<Ascii('妈'))
    val+="L";
    else if (Ascii(t1)>=Ascii('妈') && Ascii(t1)<Ascii('拿'))
    val+="M";
    else if (Ascii(t1)>=Ascii('拿') && Ascii(t1)<Ascii('哦'))
    val+="N";
    else if (Ascii(t1)>=Ascii('哦') && Ascii(t1)<Ascii('啪'))
    val+="O";
    else if (Ascii(t1)>=Ascii('啪') && Ascii(t1)<Ascii('期'))
    val+="P";
    else if (Ascii(t1)>=Ascii('期') && Ascii(t1)<Ascii('然'))
    val+="Q";
    else if (Ascii(t1)>=Ascii('然') && Ascii(t1)<Ascii('撒'))
    val+="R";
    else if (Ascii(t1)>=Ascii('撒') && Ascii(t1)<Ascii('塌'))
    val+="S";
    else if (Ascii(t1)>=Ascii('塌') && Ascii(t1)<Ascii('挖'))
    val+="T";
    else if (Ascii(t1)>=Ascii('挖') && Ascii(t1)<Ascii('昔'))
    val+="W";
    else if (Ascii(t1)>=Ascii('昔') && Ascii(t1)<Ascii('压'))
    val+="X";
    else if (Ascii(t1)>=Ascii('压') && Ascii(t1)<Ascii('匝'))
    val+="Y";
    else if (Ascii(t1)>=Ascii('匝'))
    val+="Z";
    else 
    val+="-";
    }
    return val;
    }

    public static int Ascii(char chr)
    {
    System.Text.Encoding ecode=System.Text.Encoding.GetEncoding("GB18030");
    Byte[] codeBytes=ecode.GetBytes(chr.ToString().Trim());
    if (codeBytes.Length==2)
    {
    return (int)codeBytes[0]*256+(int)codeBytes[1]-65536;
    }
    else
    {
    return (int)codeBytes[0];
    }
    }

    该文章转载自网络大本营:http://www.xrss.cn/Info/12396.Html

  • 相关阅读:
    Spring 依赖注入控制反转实现,及编码解析(自制容器)
    Bean的作用域及生命周期
    spring三种实例化bean的方式
    编码剖析Spring管理bean的原理
    Spring基本概念
    hibernate 一对一关联关系 及其懒加载,总结
    hibernate中 inverse的用法(转载)
    SpringMVC_RESTRUL_CRUD
    java 位移运算符
    三目运算中的类型转换
  • 原文地址:https://www.cnblogs.com/zhangchenliang/p/732635.html
Copyright © 2020-2023  润新知