Character encodings when writing strings to a stream

Here’s how to write a string into a stream using a given character encoding:

UTF8Encoding encoding = new UTF8Encoding();
//Encoding encoding = Encoding.GetEncoding("iso-8859-1");
byte[] bytes = encoding.GetBytes(postData);
stream.Write(bytes, 0, bytes.Length);

1 thought on “Character encodings when writing strings to a stream”

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.