a blog for those who code

Thursday, 26 June 2014

Write text files without Byte Order Mark

In this post we will be discussing about writing text files without Byte Order Mark. The below code snippet will help you to write text files without byte order mark.


In Visual Basic

Dim newVariable As New System.Text.UTF8Encoding(true)
Using streamWriter As New StreamWriter("NewFile.txt", False, newVariable)
streamWriter.WriteLine("Text goes here")
End Using

In C#

var newVariable = new System.Text.UTF8Encoding(true)
using(var streamWriter = new StreamWriter("NewFile.txt", False, newVariable)
{
    streamWriter.WriteLine("Text goes here");
}

You can omit BOM only for UTF-8 not for UTF-16. Please like and share the CodingDefined.com blog if you find it helpful and interesting.

No comments:

Post a Comment

Contact Us

Name

Email *

Message *

Sponsers

Best Hosting Plans

CC License