C # fullwidth and halfwidth Conversion

Source: Internet
Author: User

tag: OS uses the AR for file data SP C on

在计算机屏幕上,一个汉字要占两个英文字符的位置,人们把一个英文字符所占的位置称为"半角",相对地把一个汉字所占的位置称为"全角"。在汉字输入时,系统提供"半角"和"全角"两种不同的输入状态,但是对于英文字母、符号和数字这些通用字符就不同于汉字,在半角状态它们被作为英文字符处理;而在全角状态,它们又可作为中文字符处理。半角和全角切换方法:单击输入法工具条上的 按钮或按键盘上的Shift+Space键来切换。 
(1)全角--指一个字符占用两个标准字符位置。
汉字字符和规定了全角的英文字符及国标GB2312-80中的图形符号和特殊字符都是全角字符。一般的系统命令是不用全角字符的,只是在作文字处理时才会使用全角字符。
(2)半角--指一字符占用一个标准的字符位置。
通常的英文字母、数字键、符号键都是半角的,半角的显示内码都是一个字节。在系统内部,以上三种字符是作为基本代码处理的,所以用户输入命令和参数时一般都使用半角。
B 全角与半角各在什么情况下使用?
全角占两个字节,半角占一个字节。
半角全角主要是针对标点符号来说的,全角标点占两个字节,半角占一个字节,而不管是半角还是全角,汉字都还是要占两个字节。
在编程序的源代码中只能使用半角标点(不包括字符串内部的数据)
在不支持汉字等语言的计算机上只能使用半角标点(其实这种情况根本就不存在半角全角的概念)
对于大多数字体来说,全角看起来比半角大,当然这不是本质区别了。
C 全角和半角的区别
全角就是字母和数字等与汉字占等宽位置的字。半角就是ASCII方式的字符,在没有汉字输入法起做用的时候输入的字母数字和字符都是半角的。
在汉字输入法出现的时候,输入的字母数字默认为半角,但是标点则是默认为全角,可以通过鼠标点击输入法工具条上的相应按钮来改变。
D 关于“全角”和“半角”:
全角:是指中GB2312-80(《信息交换用汉字编码字符集·基本集》)中的各种符号。
半角:是指英文件ASCII码中的各种符号。

        /// 转全角的函数(SBC case)
        ///
        ///任意字符串
        ///全角字符串
        ///
        ///全角空格为12288,半角空格为32
        ///其他字符半角(33-126)与全角(65281-65374)的对应关系是:均相差65248
        ///
        public static String ToSBC(String input)
        {
            // 半角转全角:
            char[] c = input.ToCharArray();
            for (int i = 0; i < c.Length; i++)
            {
                if (c[i] == 32)
                {
                    c[i] = (char)12288;
                    continue;
                }
                if (c[i] < 127)
                    c[i] = (char)(c[i] + 65248);
            }
            return new String(c);
        }

        /**/
        // /
        // / 转半角的函数(DBC case)
        // /
        // /任意字符串
        // /半角字符串
        // /
        // /全角空格为12288,半角空格为32
        // /其他字符半角(33-126)与全角(65281-65374)的对应关系是:均相差65248
        // /
        public static String ToDBC(String input)
        {
            char[] c = input.ToCharArray();
            for (int i = 0; i < c.Length; i++)
            {
                if (c[i] == 12288)
                {
                    c[i] = (char)32;
                    continue;
                }
                if (c[i] > 65280 && c[i] < 65375)
                    c[i] = (char)(c[i] - 65248);
            }
            return new String(c);
        }

        [TestMethod]
        public void DBCTEST()
        {
            string strSBC = "中华1259test";
            string result = ToDBC(strSBC);
            Console.WriteLine(result);
            Assert.AreEqual(result,"中华1259test");
        }

C#全角和半角转换

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.