• C#汉字转为Unicode编码


    主要用于生成json格式时,将汉字转成Unicoude编码,防止页面乱码。

    protected string GetUnicode(string text)
    {
    	string result = "";
    	for (int i = 0; i < text.Length; i++)
    	{
    		if ((int)text[i] > 32 && (int)text[i] < 127)
    		{
    			result += text[i].ToString();
    		}
    		else
    			result += string.Format("\u{0:x4}", (int)text[i]);
    	}
    	return result;
    }
    

    涉及的知识点:
    1、“x”则代表十六进制,“x4”代表十六进制表示的可控制长度,如果长度不够,则用前导的0填补。
    2、Unicode写法:在表示一个Unicode的字符时,通常会用“U+”然后紧接着一组十六进制的数字来表示这一个字符。
    3、 ASCII 码(American Standard Code for Information Interchange,全称美国信息交换标准码)
    基本的 ASCII 字符集共有 128 个字符,其中有 96 个可打印字符,包括常用的字母、数字、标点符号等,另外还有 32 个控制字符。
    •0~31及127(共33个)是控制字符或通信专用字符(其余为可显示字符),如控制符:LF(换行)、CR(回车)、FF(换页)、DEL(删除)、BS(退格)、BEL(振铃)等;通信专用字符:SOH(文头)、EOT(文尾)、ACK(确认)等;ASCII值为8、9、10和13分别转换为退格、制表、换行和回车字符。它们并没有特定的图形显示,但会依不同的应用程序而对文本显示有不同的影响。
    •32~126(共95个)是字符(32sp是空格),其中48~57为0到9十个阿拉伯数字,65~90为26个大写英文字母,97~122为26个小写字母,其余为一些标点符号、运算符号等。

  • 相关阅读:
    Open source cryptocurrency exchange
    Salted Password Hashing
    95. Unique Binary Search Trees II
    714. Best Time to Buy and Sell Stock with Transaction Fee
    680. Valid Palindrome II
    Java compiler level does not match the version of the installed Java project facet.
    eclipse自动编译
    Exception in thread "main" java.lang.StackOverflowError(栈溢出)
    博客背景美化——动态雪花飘落
    java九九乘法表
  • 原文地址:https://www.cnblogs.com/sntetwt/p/11218087.html
Copyright © 2020-2023  润新知