I have the following piece of code:
Dim fecha As DateTime = DateTime.Now
Using w As StreamWriter = File.AppendText(fichero.Text)
w.WriteLine(fecha.ToString("dd/MM/yyyy") + vbTab + tiempo.Text + vbTab + comentario.Text)
w.Close()
End Using
Which is called from a Windows Form in .NET 4, where tiempo and comentario are two TextBox where you get strings. The problem I have is that if I write a localized phrase with apostrophes, they appear as “ó” “é” or “Ã-” in the text file instead of “ó” “é” and “í”.
Any idea how can I set the function to write correctly the localized phrase?
Instead of using
File.AppendTextyou can create a newStreamWriterand specify whatever encoding you like. For example 1252 for Latin (Western European languages). 2’nd parameter specifies that the text should be appended to the file.Also disposing the writer will call
Close(no need to explicitly call it)