Skip to content

Instantly share code, notes, and snippets.

@bizouarn
Last active November 21, 2023 20:16
Show Gist options
  • Save bizouarn/c68dab6c47558f92dc8b3ddf4253c1a5 to your computer and use it in GitHub Desktop.
Save bizouarn/c68dab6c47558f92dc8b3ddf4253c1a5 to your computer and use it in GitHub Desktop.
Method C# for convert String to Stream
/// <summary>
/// Generates a <see cref="Stream"/> from the given string.
/// </summary>
/// <param name="s">The input string.</param>
/// <returns>A <see cref="Stream"/> containing the data from the input string.</returns>
public static Stream GenerateStreamFromString(string s)
{
var stream = new MemoryStream();
var writer = new StreamWriter(stream);
writer.Write(s);
writer.Flush();
stream.Position = 0;
return stream;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment