C# Simple alphanumeric ASCII Code conversion

Convert letters into numbers
byte[] array = new byte[1]; // Define a set of arrays array array = System.Text.Encoding.ASCII.
GetBytes(string); //string Is the letter to be converted int asciicode = (short)(array[0]);
//asciicode Is an integer ASCII code ASCII code = Convert.ToString(asciicode);
// Will convert one ASCII Code conversion to string type
Convert numbers to letters (1)
byte[] array = new byte[1]; array[0] = (byte)(Convert.ToInt32(ASCII code ));
//ASCII Code cast binary string str=Convert.ToString(System.Text.Encoding.ASCII.GetString
(array));//str by ASCII Character corresponding to code
Convert numbers to letters (2)
System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding(); byte
[] byteArray = new byte[] { (byte)ASCII code }; string str = asciiEncoding.GetString
(byteArray);
example :
string sVer = ""; string strCheck = "10C"; string sLetter = strCheck.Substring(
2, 1); // obtain strCheck Third digit character // Get sLetter Informative Ascii Code byte[] array = new byte[1];
// Define a set of arrays array array = System.Text.Encoding.ASCII.GetBytes(sLetter);
//string Converted letters int nAsciicode = (short)(array[0]); // Determine whether it is a capital letter if (nAsciicode <=
65 || nAsciicode >= 90) continue; // Judgement sLetter All capital letters before letters for (int k = 65; k <
nAsciicode; k++) { // Will Ascii Code to uppercase System.Text.ASCIIEncoding asciiEncoding =
new System.Text.ASCIIEncoding(); byte[] byteArray = new byte[] { (byte)k };
string strCharacter = asciiEncoding.GetString(byteArray); // Spliced version . if (sVer ==
"") { if (strCheck.Length == 3) { sVer = strCheck.Substring(0, 2) + strCharacter
; } else { sVer = strCheck.Substring(0, 2) + strCharacter + strCheck.Substring(3
, strCheck.Length - 3); } } else { if (strCheck.Length == 3) { sVer += "," +
strCheck.Substring(0, 2) + strCharacter; } else { sVer += "," + strCheck.
Substring(0, 2) + strCharacter + strCheck.Substring(3, strCheck.Length - 3); } }
}
The running result of the above instance should be :10A,10B

A thousand mile trip begins with one step. , We should encourage each other !

Technology
©2019-2020 Toolsou All rights reserved,
Solve in servlet The Chinese output in is a question mark C String function and character function in language MySQL management 35 A small coup optimization Java performance —— Concise article Seven sorting algorithms (java code ) use Ansible Batch deployment SSH Password free login to remote host according to excel generate create Build table SQL sentence Spring Source code series ( sixteen )Spring merge BeanDefinition Principle of Virtual machine installation Linux course What are the common exception classes ?