How to take a string constructor and convert it to streamReader?

How to take a string constructor and convert it to a stream?

SO my stringbuilder needs to be converted to:

StreamReader stream = ???? 

Update

I tried using a line reader, for example:

 StringReader sr = new StringReader(sb.ToString()); StreamReader stream = new StreamReader(sr); 

but it doesn’t work?

+6
c # stream streamreader
source share
2 answers

Use ToString to convert StringBuilder to String and use StringReader to wrap String as a Stream.

+8
source share

If you use StreamReader , you need to convert the string to a memory stream, and then create a new StreamReader using this object:

 StreamReader reader= new StreamReader( new MemoryStream(Encoding.ASCII.GetBytes(sb.ToString()))); 
+6
source share

All Articles