Explore? How to get a double-byte character of the ASCII code in C #

xiaoxiao2021-03-06  103

I used VB before I quickly got this desired result:

DIM Ascstr as string = asc (TextBox.text (0))

But I used C #, which seems simple to this seem simpler, and I have exhausted my brain.

String ascstr = (int) textbox1.text [0];

Can deal with Abcd ..... and _ (), but there is no way to "I, you, he", don't believe you try:

Compare VB's ASC - C # INT value: VB (ASC) I: -12590C # (int) me: 25105, minus (2 ^ 16 = 65536) is: -40431 cry ... I Reading, can't find, see help. But C # does trouble, a lot of things don't know, what asciiencoding, the result is 63, explaining the encoding that cannot be identified, this is good, as long as it is Chinese, all 63, try UTF8, Unicode, really unknown Cloud, usually too unfamiliar with the encoding. Finally, use the Encoding class, but it still can't get the result. Find ah, find ...

Encoding ecode = encoding.getencoding ("GB18030"); start writing code:

Encoding ecode = encoding.getencoding ("GB18030"); Byte [] codebytes = ecode.getbytes (chr.tostring ()); messagebox.show (codeBytes [0] .tostring ()); result got a hundred digits Value, no. Suddenly I thought that the Chinese words were double-bytes, and they used a function to judge whether the character is double byte ///

// is a double-byte character. /// public static bool istwobyteschar (char chr) {string str = chr.tostring (); // Using Chinese support encoded encode = Encoding.Getencoding ("GB18030"); if (ecode.getbytecount ) == 2) {RETURN TRUE;} else {return false;}} Ok, come to get this ASCII code: /// // get a character's ASCII code /// Public Static INT ASCII (Char chr) {Encoding Ecode = Encoding.Getencoding ("GB18030"); Byte [] codeBytes = Ecode.getbytes (chr.tostring ()); if (istwobyteschar (chr)) {// Dual Number code Highlight 256, then add low // This is no symbol, then minus 65536 return (int) codebytes [0] * 256 (int) codeBYTES [1] - 65536;} else {return (int) codebook [0] }} Test: Enter "I" finally got you: -12590 I don't know what to do, for this simple function, it seems to go to Huangshan to travel, and the boat first to the Americas, then go to the Americas Europe, then go to the Three Gorges, go to Huangshan. Just because I can't find a special car to Huangshan.

If anyone knows, let's tell. But it doesn't matter, I am enough for my scenery.

转载请注明原文地址:https://www.9cbs.com/read-105411.html

New Post(0)