In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how C#generates Chinese character coding, which is introduced in great detail and has certain reference value. Interested friends must read it!
C#Generation Chinese Character Coding Principle
How do you generate characters randomly? Where do Chinese characters come from? Is there a background data table, which stores all the required Chinese characters, using the program to randomly extract a few Chinese character combinations on the line? Use the background database to save all Chinese characters and take them out randomly when using them. This is also a way, but there are so many Chinese characters, how to make them? In fact, you can do all this without using any background database. To know how to generate Chinese characters, we must first understand the coding principle of Chinese characters.
In 1980, in order to make every Chinese character have a national unified code, China promulgated *** national standards for Chinese character coding: GB2312-80 Basic Set of Chinese Character Coding for Information Interchange, abbreviated as GB2312. This character set is the development basis of Chinese information processing technology in China and is also the unified standard for all Chinese character systems in China. Later, the national standard GB18030 -2000 "Extension of the Basic Set of Chinese Character Coding for Information Interchange" was published, referred to as GB18030. If coding and localization are involved in programming, friends should be familiar with GB18030. This is the most important Chinese character coding standard after GB2312-1980 and GB13000 -1993, and it is also one of the basic standards that our computer system must follow in the future.
Analysis of Chinese Character Coding Principle by. Net Program
System.Text can be used in. Net to handle encoding for all languages. The System.Text namespace contains a number of encoded classes for manipulation and conversion. Among them, the Encoding class is the class that focuses on processing Chinese character coding. By querying the methods of the Encoding class in the. NET documentation, we can see that everything related to text encoding is a byte array, and there are two very useful methods:
◆Encoding.GetBytes () method encodes all or part of the contents of a specified String or character array into a byte array
The Encoding.GetString () method decodes the specified byte array into a string.
using System; using System.Text; namespace ConsoleApplication { class ChineseCode { public static void Main() { //Get GB2312 encoding page (table) Encoding gb=Encoding.GetEncoding("gb2312"); //Call the function to generate 4 random Chinese character codes object[] bytes=CreateRegionCode(4); //decode Chinese character string str1=gb.GetString((byte[])Convert.ChangeType according to byte array of Chinese character encoding (bytes[0], typeof(byte[]))); string str2=gb.GetString((byte[])Convert.ChangeType (bytes[1], typeof(byte[]))); string str3=gb.GetString((byte[])Convert.ChangeType (bytes[2], typeof(byte[]))); string str4=gb.GetString((byte[])Convert.ChangeType(bytes[3], typeof(byte[]))); //Console.WriteLine(str1 + str2 +str3 +str4); } The above is all the content of this article,"How to generate Chinese character coding with C#", thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.