How to

convert string to stream

Published: 11. January 2014 | Updated: 11. January 2014
License: Microsoft Public License (MS-PL)
Categories: Converting, Streams
Tags: C# Conversion
Was this snippet helpful for you? YESYES / NONO
Get Analyzant!

Check your entire website from code to content in minutes with Analyzant, the free analysis suite.

Free download at analyzant.com

Import namespaces

using System.IO;
using System.Text;

Code

public static Stream StringToStream(string text, Encoding encoding = null)
{
    encoding = encoding ?? Encoding.UTF8;
    Stream stream = new MemoryStream(encoding.GetBytes(text));
    return stream;
}
Send us feedback about this snippet »



Related Snippets: