String to Stream

Sometimes a string isn't enough, you need a stream. Unfortunately, there isn't a direct method to stick a string into a stream. But we are saved! MemoryStream will take bytes... here's how to convert your string into a series of bytes so you can get that all important StringStream. No, I'm not going to make a StringStream class though you certainly can fulfill your masochistic class explosion desires.

String request = "I can has cheezburger?";

MemoryStream stream = new MemoryStream(Encoding.Unicode.GetBytes(request));

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Print | posted on Thursday, August 07, 2008 5:37 PM

Comments on this post

No comments posted yet.

Your comment:

 (will show your gravatar)