我有一些C++代碼,通過STL字符串將字節值保存到文件中&文本I/O,並且對如何在C#中執行此操作感到困惑。C#字節數組到字符串,反之亦然
首先我轉換字節數組爲字符串每個&存儲爲一個文本文件中的一行:
StreamWriter F
loop
{
byte[] B; // array of byte values from 0-255 (but never LF,CR or EOF)
string S = B; // I'd like to do this assignment in C# (encoding? ugh.) (*)
F.WriteLine(S); // and store the byte values into a text file
}
後...我想扭轉步驟,回到原始字節值:
StreamReader F;
loop
{
string S = F.ReadLine(); // read that line back from the file
byte[] B = S; // I'd like to convert back to byte array (*)
}
你如何做這些任務(*)?
[.NET String to byte Array C#]的可能重複(http://stackoverflow.com/questions/472906/net-string-to-byte-array-c-sharp) – TGO
有點含糊......你想獲得這些字節的文本表示? IE:'byte [] {0,1,2,3}'變成'「0 1 2 3」'? – Corey