2

重複の可能性:
.NET 16進値の文字列からUnicode文字への変換(異なるコードページをサポート)

ASCII文字列を含む文字列をテキストに変換しようとすると、Byte []から変換するSystem.Text.ASCIIEncoding.ASCII.GetStringしか見つからないようですが、この状況ではそれを実行できるようにしたいと思います。文字列から。

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

このための組み込み関数はありますか?助けていただければ幸いです、ありがとうございます。

4

1 に答える 1

7
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);
}
于 2012-04-27T11:50:12.363 に答える