亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#字符串和Acsii碼相互轉(zhuǎn)換

 更新時(shí)間:2023年02月06日 15:30:25   作者:新時(shí)代丘鳴山  
本文主要介紹了C#字符串和Acsii碼相互轉(zhuǎn)換,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

1,現(xiàn)在因?yàn)橛龅揭粋€(gè)讀取pdf文件文本信息遇到亂么問(wèn)題,才找到這個(gè)文本字符串的編碼轉(zhuǎn)換的實(shí)現(xiàn)方式來(lái)判斷是否存在亂碼(0>亂碼>255):

C# 字符轉(zhuǎn)ASCII碼,ASCII碼轉(zhuǎn)字符

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碼轉(zhuǎn)字符:

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

還有一個(gè)特殊的方式:直接獲取字符串的字節(jié)大小來(lái)區(qū)分

string str="abcd";
byte[] bytetest = System.Text.Encoding.Default.GetBytes(str.ToString());

到此這篇關(guān)于C#字符串和Acsii碼相互轉(zhuǎn)換的文章就介紹到這了,更多相關(guān)C#字符串和Acsii碼轉(zhuǎn)換內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論