Last active
November 21, 2023 20:16
-
-
Save bizouarn/c68dab6c47558f92dc8b3ddf4253c1a5 to your computer and use it in GitHub Desktop.
Method C# for convert String to Stream
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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