zoukankan      html  css  js  c++  java
  • 字符串转换(全角/半角)

     1 /// <summary>
     2   /// 字符串转换(全角/半角)
     3   /// </summary>
     4   public class BCCase
     5   {
     6     private BCCase() { }
     7 
     8     private static BCCase _instance = new BCCase();
     9 
    10     public static BCCase _
    11     {
    12       get { return _instance; }
    13       set { _instance = value; }
    14     }
    15 
    16     #region 全角转换
    17     /// <summary>
    18     /// 全角转换
    19     /// </summary>
    20     /// <param name="input">全角字符</param>
    21     /// <returns>输出半角</returns>
    22     public string GetSBC(string input)
    23     {
    24       char[] c = input.ToCharArray();
    25       for (int i = 0; i < c.Length; i++)
    26       {
    27         byte[] b = System.Text.Encoding.Unicode.GetBytes(c, i, 1);
    28         if (b.Length == 2)
    29         {
    30           if (b[1== 0)
    31           {
    32             b[0= (byte)(b[0- 32);
    33             b[1= 255;
    34             c[i] = System.Text.Encoding.Unicode.GetChars(b)[0];
    35           }
    36         }
    37       }
    38       string strNew = new string(c);
    39       return strNew;
    40     }
    41     #endregion
    42 
    43     #region 半角转换
    44     /// <summary>
    45     /// 半角转换
    46     /// </summary>
    47     /// <param name="input">半角字符</param>
    48     /// <returns>输出全角</returns>
    49     public string GetDBC(string input)
    50     {
    51       char[] c = input.ToCharArray();
    52       for (int i = 0; i < c.Length; i++)
    53       {
    54         byte[] b = System.Text.Encoding.Unicode.GetBytes(c, i, 1);
    55         if (b.Length == 2)
    56         {
    57           if (b[1== 255)
    58           {
    59             b[0= (byte)(b[0+ 32);
    60             b[1= 0;
    61             c[i] = System.Text.Encoding.Unicode.GetChars(b)[0];
    62           }
    63         }
    64       }
    65       string strNew = new string(c);
    66       return strNew;
    67     }
    68     #endregion
    69   }
    70 
  • 相关阅读:
    异常 中断 陷阱
    关于delete字符串 需不需要加 [ ]
    关于联合体输出的问题(是否小端模式)
    String reorder
    数据库 ---5 索引 创建用户及授权 数据备份
    数据库 --- 4 多表查询 ,Navicat工具 , pymysql模块
    数据库 --- 3 行(记录)操作 单表查询
    数据库 --- 2 库 ,表
    数据库 --- 1 初始 数据库
    并发 --- 5 线程的其他方法 线程队列 线程池 协程
  • 原文地址:https://www.cnblogs.com/tearer/p/1778256.html
Copyright © 2011-2022 走看看