简体   繁体   English

将本地化字符串写入本地化文件

[英]Write localized string to localized file

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. 这是从.NET 4中的Windows窗体调用的,其中tiempocomentario是两个用于获取字符串的TextBox。 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.AppendText you can create a new StreamWriter and specify whatever encoding you like. 您可以创建一个新的StreamWriter并指定所需的编码,而不是使用File.AppendText For example 1252 for Latin (Western European languages). 例如拉丁语(西欧语言)为1252。 2'nd parameter specifies that the text should be appended to the file. 2'nd参数指定文本应附加到文件中。

Using writer = New StreamWriter(fichero.Text, True, Encoding.GetEncoding(1252))
    writer.WriteLine(fecha.ToString("dd/MM/yyyy") + vbTab + tiempo.Text + vbTab + comentario.Text)
End Using

Also disposing the writer will call Close (no need to explicitly call it) 另外,处理程序将调用Close (无需显式调用它)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM