Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write to a file in Unicode in Vb.Net

How should I modify the following Vb.Net code to write str to the file in unicode?

Do I need to convert str to Unicode before writing to the file?

Using sw As StreamWriter = New StreamWriter(fname)
    sw.Write(str)
    sw.Close()
End Using
like image 835
CJ7 Avatar asked Jun 11 '10 09:06

CJ7


1 Answers

Use the overriden constructor to specify the encoding

Using sw As StreamWriter = New StreamWriter(fname, true, System.Text.Encoding.Unicode)
    sw.Write(str)
    sw.Close()
End Using

Pick either UTF8(8bit) or Unicode(16 bit) character-set encoding as per your requirements.

like image 163
Nimesh Madhavan Avatar answered Sep 28 '22 00:09

Nimesh Madhavan