私はこの質問がスタックオーバーフローで2回前に尋ねられたことを知っていますが、今回はデータの値を変更しない方法で最も保証された方法を求めています。私は文字列からバイト[]に変換してから文字列に変換したい。あなたはまだ、私が欲しいものを取得しない場合、私はどの知りたいbyte []とstringの間の変換に最適な方法は?
private string ToString(byte[] bytes)
{
string response = string.Empty;
foreach (byte b in bytes)
response += (Char)b;
return response;
}
:
string s2 = BitConverter.ToString(bytes); // 82-C8-EA-17
String[] tempAry = s2.Split('-');
byte[] decBytes2 = new byte[tempAry.Length];
for (int i = 0; i < tempAry.Length; i++)
{
decBytes2[i] = Convert.ToByte(tempAry[i], 16);
}
または以下のコード:私はByteConverter
、Convert
、Encoding
、BitConverter
、HttpServerUtility.UrlTokenEncode/HttpServerUtility.UrlTokenDecode
次のコードを使用することができます私はどの方法を使うべきかを知りたい。ねえ、私はネットワーク上でこの配列を送信するので、私は最小サイズのバイト配列を好むだろう、私は最初の256バイトを使用します。
データ量['Convert.ToBase64String']を使用したい場合は(https://msdn.microsoft.com/en-us/library/system.convert.tobase64string(v = vs.110) ).aspx)は、上記のすべての項目よりもはるかに短い文字列を提供します。 –
また、「バイト配列を16進文字列に変換する方法とその逆の方法」の質問は何ですか?(http://stackoverflow.com/questions/311165/how-do-you-convert-byte-array-to -hexadecimal-string-and-vice-versa) "あなたのためにカバーしていない? –