C # simple alpha-numeric ASCII code conversion

Source: Internet
Author: User

Convert letters into numbers

byte[] array = new BYTE[1]; Defines a set of array arrays
Array = System.Text.Encoding.ASCII.GetBytes (string); The letter of a string conversion
int asciicode = (short) (array[0]); /* Why ask Hovertree.com * *
ASCII code = convert.tostring (Asciicode); Converts an ASCII code to a string type

Convert numbers into letters
byte[] array = new BYTE[1];
Array[0] = (byte) (Convert.ToInt32 (ASCII code)); ASCII forced conversion binary
Converted letter = convert.tostring (System.Text.Encoding.ASCII.GetString (array));

Many times in the coding process will be used to convert certain numbers of index into letters, such as Excel cells in the number of columns in Excel in uppercase letters, to be converted to letters can use C # ASCIIEncoding class in the GetString method. See the following example:

/// ///number to letter/// ///number to convert to letters (number range in closed interval [65,90])/// Private stringNuntochar (intNumber ) {         if( $<= number && ->=Number ) {System.Text.ASCIIEncoding ASCIIEncoding=NewSystem.Text.ASCIIEncoding (); byte[] Btnumber =New byte[] { (byte) Number}; returnasciiencoding.getstring (Btnumber); }        return "the number is not within the conversion range";} /// ///convert,..., 35,36 to a,b,c,..., y,z/// ///number to convert to letters (number range in closed interval [1,36])/// Private stringNunbertochar (intNumber ) {        if(1<= number && $>=Number ) {                intnum = number+ -; System.Text.ASCIIEncoding asciiencoding=NewSystem.Text.ASCIIEncoding (); byte[] Btnumber =New byte[] { (byte) num}; returnasciiencoding.getstring (Btnumber); }        return "the number is not within the conversion range";}/*how to ask Hovertree.com*/

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

C # simple alpha-numeric ASCII code conversion

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.