C # simple conversion of letters, numbers, ASCII codes,

Source: Internet
Author: User

C # simple conversion of letters, numbers, ASCII codes,

Convert letters to numbers

Byte [] array = new byte [1]; // defines an array
Array = System. Text. Encoding. ASCII. GetBytes (string); // string Conversion letter
Int asciicode = (short) (array [0]);/* Ask hovertree.com */
ASCII code = Convert. ToString (asciicode); // Convert the ASCII code to the string type

 

Convert numbers to letters
Byte [] array = new byte [1];
Array [0] = (byte) (Convert. ToInt32 (ASCII Code); // the ASCII code is forcibly converted to binary
Converted letters = Convert. ToString (System. Text. Encoding. ASCII. GetString (array ));

 

 

 

In the encoding process, indexes of some numbers are often used to convert to letters. For example, the number of columns of cells in Excel is represented by uppercase letters, to convert a number to a letter, use the GetString method in the ASCIIEncoding class of C. See the following example:

 

///// Convert a number to a letter // the number to be converted to a letter (the number range is []) // private string NunToChar (int number) {if (65 <= number & 90> = number) {System. text. ASCIIEncoding asciiEncoding = new System. text. ASCIIEncoding (); byte [] btNumber = new byte [] {(byte) number}; return asciiEncoding. getString (btNumber);} return "the number is not in the conversion range";} // set 1, 2, 3 ,..., 35, 36 to A, B, C ,..., y, Z // the number to be converted to a letter (the number range is [1, 36]) // private string NunberToChar (int number) {if (1 <= number & 36> = number) {int num = number + 64; System. text. ASCIIEncoding asciiEncoding = new System. text. ASCIIEncoding (); byte [] btNumber = new byte [] {(byte) num}; return asciiEncoding. getString (btNumber);} return "the number is not in the conversion range";}/* He asked hovertree.com */

Recommended: http://www.cnblogs.com/roucheng/p/netkuangjia.html

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.