将字符串转换为流 [英] Converting a string to stream

查看:82
本文介绍了将字符串转换为流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有2-3行简单的方法可以做到这一点吗?

Is there any 2-3 line simple way to do this?
Thanks.

推荐答案

byte [] byteArray = Encoding.ASCII.GetBytes(test);
MemoryStream流=新的MemoryStream(byteArray);
byte[] byteArray = Encoding.ASCII.GetBytes( test );
MemoryStream stream = new MemoryStream( byteArray );


byte[] byteArray = Encoding.ASCII.GetBytes(test); 
MemoryStream stream = new MemoryStream(byteArray);



您可能已经在google上找到了它.

编辑==================



You could have found this with google.

EDIT ==================

string test = "My test string.";
byte[] byteArray = Encoding.ASCII.GetBytes(test); 
MemoryStream stream = new MemoryStream(byteArray);



它对我来说很好. (使用.Net 4.0,但是对于任何版本的.Net都应该是不错的.)



It works just fine for me. (using .Net 4.0, but it should be good for any version of .Net).


字符串值="Hello World";
System.IO.StringReader reader =新的System.IO.StringReader(value);

通过avigdose:
http://www.codeproject.com/script/Membership/View.aspx?mid=1909728 [ ^ ]
string value = "Hello World";
System.IO.StringReader reader = new System.IO.StringReader(value);

by avigdose:
http://www.codeproject.com/script/Membership/View.aspx?mid=1909728[^]


这篇关于将字符串转换为流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆