2012-04-27 19 views
2

可能な重複ASCIIの文字列を変換する:テキストにASCII文字列を含む文字列を変換するために探し
.NET Convert from string of Hex values into Unicode characters (Support different code pages)は、通常の文字列のC#に

を、私だけのことができるようにしているように見えますByte []から変換するSystem.Text.ASCIIEncoding.ASCII.GetStringを見つけてください。このような状況では、文字列から変換することができます。

its a string containing ASCII hex: For example : ASCI = 47726168616D would equal Graham

このための機能で構築された任意のはありますか?助けていただければ幸いです。ありがとうございます。

+2

あなたのコードPlease –

+3

C#の通常の文字列とは何ですか? – mloskot

+4

@Graham文字列をbyte []に​​変換してからSystem.Text.ASCIIEncoding.ASCII.GetStringを適用してみてください – Milee

答えて

6
private static string GetStringFromAsciiHex(String input) 
{ 
    if (input.Length % 2 != 0) 
     throw new ArgumentException("input"); 

    byte[] bytes = new byte[input.Length/2]; 

    for (int i = 0; i < input.Length; i += 2) 
    { 
     // Split the string into two-bytes strings which represent a hexadecimal value, and convert each value to a byte 
     String hex = input.Substring(i, 2); 
     bytes[i/2] = Convert.ToByte(hex, 16);     
    } 

    return System.Text.ASCIIEncoding.ASCII.GetString(bytes); 
} 
関連する問題