梁济时

面向对象,设计模式,微服务架构,Java

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

using System;
using System.Collections.Generic;
using System.Text;

namespace talefox.ShareLib
{
    public class Characters
    {
        /// <summary>
        /// 全角转半角
        /// </summary>
        /// <param name="c">需要转换的字符,当为半角时不转换</param>
        /// <returns>半角字符</returns>
        public static char DoubleByteToHalfAngle(char c)
        {
            char[] cs = new char[] { c};
            byte[] bs = System.Text.Encoding.Unicode.GetBytes(cs, 0, 1);

            if (bs.Length == 2)
            {
                if (bs[1] == 255)
                {
                    bs[0] = (byte)(bs[0] + 32);
                    bs[1] = 0;
                    cs[0] = System.Text.Encoding.Unicode.GetChars(bs)[0];
                }
            }
            return cs[0];
        }
    }
}

posted on 2008-10-30 00:06  传说中的狐狸  阅读(249)  评论(0编辑  收藏  举报