首页 > Windows开发 > 详细

C#-判断字符是否是全角半角

时间:2019-07-23 14:00:48      阅读:85      评论:0      收藏:0      [点我收藏+]

  C#字符串的全角是指用二个字节来表示的一个字符

  C#字符串的半角是用一个字节来表示的一个字符

  这样的话我们就可以用string.length 和System.text.Encoding.Default.GetByteCount来判断

  其中string.length表示C#字符串字符串的字符数,

  System.text.Encoding.Default.GetByteCount表示字符串的字节数。

 

            string checkString = textBox1.Text.ToString();
            for (int counter = 0; counter < checkString.Length; counter++)
            {
                if (2 * checkString[counter].ToString().Length == Encoding.Default.GetByteCount(checkString[counter].ToString()))
                {
                    MessageBox.Show("full width" + checkString[counter].ToString() + "[" + (counter+1) + "]");
                }

            }

 

 

参考:https://www.cnblogs.com/jhxk/articles/1738968.html

C#-判断字符是否是全角半角

原文:https://www.cnblogs.com/JinweiChang/p/11231267.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!