How to take a stringbuilder and convert it to a streamReader?

Blankman picture Blankman · Feb 21, 2010 · Viewed 13.9k times · Source

How to take a stringbuilder and convert it to a stream?

SO my stringbuilder has to be converted into a :

StreamReader stream = ????

Update

I tried using a stringreader like:

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

but that doesn't work?

Answer

Andy Jacobs picture Andy Jacobs · Feb 21, 2010

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