- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace ConsoleApp1
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- string n= "中国".charCodeAt(1);
- Console.WriteLine(n);
-
- n = "中华人民共和国".charCodeAt();
- Console.WriteLine(n);
-
- }
-
- }
- public static class A
- {
- public static string charCodeAt(this string character,int index)
- {
- return (character[index]+"").charCodeAt();
- }
- public static string charCodeAt(this string character)
- {
-
- string coding = "";
- for (int i = 0; i < character.Length; i++)
- {
- byte[] bytes = System.Text.Encoding.Unicode.GetBytes(character.Substring(i, 1));
-
- //取出二进制编码内容
- string lowCode = System.Convert.ToString(bytes[1], 16);
-
- //取出低字节编码内容(两位16进制)
- if (lowCode.Length == 1)
- {
- lowCode = "0" + lowCode;
- }
-
- string hightCode = System.Convert.ToString(bytes[0], 16);
-
- //取出高字节编码内容(两位16进制)
- if (hightCode.Length == 1)
- {
- hightCode = "0" + hightCode;
- }
-
- coding += (hightCode + lowCode);
-
- }
-
- return coding;
- }
- }
- }