• 全半角转化


      #region 全半角转化
            /// <summary>全角半角的相互转换
            ///
            /// </summary>
            public class ConvertDBCAndSBC
            {

                /// <summary>半角转成全角
                /// 半角空格32,全角空格12288
                /// 其他字符半角33~126,其他字符全角65281~65374,相差65248
                /// </summary>
                /// <param name="input"></param>
                /// <returns></returns>
                public static string DBCToSBC(string input)
                {
                    char[] cc = input.ToCharArray();
                    for (int i = 0; i < cc.Length; i++)
                    {
                        if (cc[i] == 32)
                        {
                            // 表示空格
                            cc[i] = (char)12288;
                            continue;
                        }
                        if (cc[i] < 127 && cc[i] > 32)
                        {
                            cc[i] = (char)(cc[i] + 65248);
                        }
                    }
                    return new string(cc);
                }

                /// <summary>全角转半角
                /// 半角空格32,全角空格12288
                /// 其他字符半角33~126,其他字符全角65281~65374,相差65248
                /// </summary>
                /// <param name="input"></param>
                /// <returns></returns>
                public static string SBCToDBC(string input)
                {
                    char[] cc = input.ToCharArray();
                    for (int i = 0; i < cc.Length; i++)
                    {
                        if (cc[i] == 12288)
                        {
                            // 表示空格
                            cc[i] = (char)32;
                            continue;
                        }
                        if (cc[i] > 65280 && cc[i] < 65375)
                        {
                            cc[i] = (char)(cc[i] - 65248);
                        }

                    }
                    return new string(cc);
                }
            }

            #endregion

  • 相关阅读:
    c# GDI+中发生一般性错误的解决办法
    AutoMapper ProjectTo 与 Mapster ProjectToType
    c# 无法加载 DLL“SQLite.Interop.DLL”: 找不到指定的模块
    c# 剪裁图片
    c# System.InvalidOperationException:“在创建窗口句柄之前,不能在控件上调用 Invoke 或 BeginInvoke
    如何生成自己的二维码qrcode模块的使用
    Firefox20 到 Firefox21 的一个小改变
    修改document.domain的注意事项
    ✍59 300I显卡测试总结
    ✍57 PiPy上传模块&Linux 拆分合并
  • 原文地址:https://www.cnblogs.com/lmcblog/p/2596517.html
Copyright © 2020-2023  润新知