zoukankan      html  css  js  c++  java
  • c# asp.net 2.0 半角专全角,全角专半角

     /// <summary>
            
    /// 半角转全角
            
    /// </summary>
            
    /// <param name="BJstr"></param>
            
    /// <returns></returns>

            static public string GetQuanJiao(string BJstr)
            
    {
                
    #region
                
    char[] c = BJstr.ToCharArray();
                
    for (int i = 0; i < c.Length; i++)
                
    {
                    
    byte[] b = System.Text.Encoding.Unicode.GetBytes(c, i, 1);
                    
    if (b.Length == 2)
                    
    {
                        
    if (b[1== 0)
                        
    {
                            b[
    0= (byte)(b[0- 32);
                            b[
    1= 255;
                            c[i] 
    = System.Text.Encoding.Unicode.GetChars(b)[0];
                        }

                    }

                }


                
    string strNew = new string(c);
                
    return strNew;

                
    #endregion

            }


            
    /// <summary>
            
    /// 全角转半角
            
    /// </summary>
            
    /// <param name="QJstr"></param>
            
    /// <returns></returns>

            static public string GetBanJiao(string QJstr)
            
    {
                
    #region
                
    char[] c = QJstr.ToCharArray();
                
    for (int i = 0; i < c.Length; i++)
                
    {
                    
    byte[] b = System.Text.Encoding.Unicode.GetBytes(c, i, 1);
                    
    if (b.Length == 2)
                    
    {
                        
    if (b[1== 255)
                        
    {
                            b[
    0= (byte)(b[0+ 32);
                            b[
    1= 0;
                            c[i] 
    = System.Text.Encoding.Unicode.GetChars(b)[0];
                        }

                    }

                }

                
    string strNew = new string(c);
                
    return strNew;
                
    #endregion

            }

     3、关于全角转半角的问题,在Unicode中,标点、数字、字母的半角编码最高位均为0,它们的全角编码与半角编码的第三位相差32h。
  • 相关阅读:
    Python笔记_第四篇_高阶编程_再议装饰器和再议内置函数
    Python笔记_第四篇_高阶编程_实例化方法、静态方法、类方法和属性方法概念的解析。
    Python笔记_第四篇_高阶编程_二次封装
    Python笔记_第四篇_高阶编程_反射_(getattr,setattr,deattr,hasattr)
    Python笔记_第四篇_高阶编程_正则表达式_3.正则表达式深入
    Python笔记_第四篇_高阶编程_正则表达式_2.正则表达式入门
    Python笔记_第四篇_高阶编程_正则表达式_1.正则表达式简介(re模块)
    Python笔记_第四篇_高阶编程_检测_2.文档检测
    愿你的眼中总有光芒,活成你想要的模样!
    ruby-rails 环境搭建
  • 原文地址:https://www.cnblogs.com/lds85930/p/1207750.html
Copyright © 2011-2022 走看看