zoukankan      html  css  js  c++  java
  • C# Chr to ASCLL and ASCLL to Chr

    在VB中有ASC和Chr系统定义的函数可用,在C#中是没有的...

    这次是因为条码需要增加一位校验码,需要使用到这个转换函数。 

    字符ASCII码 

    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.");
       }
      }

             

                成长

           /      |     \

        学习   总结   分享

    QQ交流群:122230156

  • 相关阅读:
    P2018 消息传递[dp]
    P1436 棋盘分割[dp]
    一条线段引发的思考
    浅谈树上差分
    P2680 运输计划[二分+LCA+树上差分]
    P1600 天天爱跑步[桶+LCA+树上差分]
    P4560 [IOI2014]Wall 砖墙
    P1311 选择客栈[模拟]
    P1314 聪明的质监员[二分答案]
    Linux snmp导入MIB库
  • 原文地址:https://www.cnblogs.com/benio/p/2135716.html
Copyright © 2011-2022 走看看