public static int Asc(string character)
   {
    if (character.Length == 1)
    {
     System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
     int intAsciiCode = (int)asciiEncoding.GetBytes(character)[0];
     return (intAsciiCode);
    }
    else
    {
     throw new Exception("Character is not valid.");
    }

   }

ASCII码转字符:

public static string Chr(int asciiCode)
   {
    if (asciiCode >= 0 && asciiCode <= 255)
    {
     System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
     byte[] byteArray = new byte[] { (byte)asciiCode };
     string strCharacter = asciiEncoding.GetString(byteArray);
     return (strCharacter);
    }
    else
    {
     throw new Exception("ASCII Code is not valid.");
    }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
猜你喜欢
  • 2022-01-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-03
相关资源
相似解决方案