. Net UCS2 is the easiest way to add code

Source: Internet
Author: User

. Net UCS2 plus codeThe simplest method. Recently, I developed a text message Gateway application. Although it is not as troublesome as PDUS, it is necessary to add a code for sending a Chinese text message (BTW does not need to be used in the end ).

The detailed name of the programming document should be UCS2 with codes, OK, UTF8 and 16. No stranger to everyone, but what is UCS2? Here, I will give a rough explanation.

  The UCS has two formats: UCS-2 and UCS-4.As the name suggests, UCS-2 is to use two bytes of encoding, UCS-4 is to use 4 bytes (actually only 31 bits, the highest bit must be 0) encoding. Let's make some simple mathematical games:

 

UCS-2 has 2 ^ 16 = 65536 bits, UCS-4 has 2 ^ 31 = 2147483648 bits.

 

The UCS-4 is divided into 2 ^ 7 = 128 groups based on the highest byte with the highest bit of 0. Each group is further divided into 256 plane Based on the next high byte. Each plane is divided into 3rd rows (rows) based on 256 bytes, and each row contains 256 cells. Of course, cells in the same row are only different from the last byte, and the rest are the same.

The plane 0 of group 0 is called Basic Multilingual Plane, that is, BMP. Or in the UCS-4, the code bit with the height of two bytes 0 is called BMP.

Remove the bmp of the UCS-4 from the first two zero bytes to get the UCS-2. Add two zero bytes before the two bytes of the UCS-2 to get the bmp of the UCS-4. Currently, the UCS-4 specification does not contain any characters other than BMP.

 

After countless attempts, I used the following code to complete the code-added function. The test passed, and the test was complete!

 

The following is a reference clip:
Private Function StrtoUCS2 (ByVal Content As String) As String
Dim I, count As Integer
Dim Result, t As String
For I = 1 To Content. Length
T = Format (AscW (Mid (Content, I), "X ")
For count = 1 To 4-t. Length
T = "0" & t
Next
Result + = t
Next
Return Result
End Function

Related Article

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.