using System;
using System.IO;
using System.Text;
namespace CSharpConvertString2Stream
{
class Program
{
static void Main( string[] args )
{
string str = "Testing 1-2-3"; //convert string 2 stream
byte[] array = Encoding.ASCII.GetBytes(str);
MemoryStream stream = new MemoryStream(array); //convert stream 2 string
StreamReader reader = new StreamReader(stream);
string text = reader.ReadToEnd();
Console.WriteLine(text);
Console.ReadLine();
}
}
}
using System.IO;
using System.Text;
namespace CSharpConvertString2Stream
{
class Program
{
static void Main( string[] args )
{
string str = "Testing 1-2-3"; //convert string 2 stream
byte[] array = Encoding.ASCII.GetBytes(str);
MemoryStream stream = new MemoryStream(array); //convert stream 2 string
StreamReader reader = new StreamReader(stream);
string text = reader.ReadToEnd();
Console.WriteLine(text);
Console.ReadLine();
}
}
}
本文展示了如何使用C#将字符串转换为字节数组,然后通过内存流进行操作,最后将流转换回原始字符串的过程。
3762

被折叠的 条评论
为什么被折叠?



