Convert letters to numbers
Byte [] array = new byte [1]; // defines an array Array
Array = system. Text. encoding. ASCII. getbytes (string); // String Conversion letter
Int asciicode = (short) (array [0]);
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 numbers to letters
///
/// Number to be converted to a letter (the number range is [])
///
Private string nuntochar (INT number)
{
If (65 <= Number & 90> = number)
{
System. Text. asciiencoding = new system. Text. asciiencoding ();
Byte [] btnumber = new byte [] {(byte) number };
Return asciiencoding. getstring (btnumber );
}
Return "the number is not in the conversion range ";
}
///
/// Convert 1, 2, 3,..., 35, 36 to A, B, C,..., Y, Z
///
/// 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 = new system. Text. asciiencoding ();
Byte [] btnumber = new byte [] {(byte) num };
Return asciiencoding. getstring (btnumber );
}
Return "the number is not in the conversion range ";
}