[英]system.io.streamwriter on .net compact framework accents
well i am using all these codes: 好吧,我正在使用所有这些代码:
// StreamWriter file = new StreamWriter(AppSettings.Instance.Dpath + "\\notaventa.txt");
// StreamWriter file = new StreamWriter(AppSettings.Instance.Dpath + "\\notaventa.txt", false, System.Text.Encoding.GetEncoding(1252));
' Dim objEscritor = New StreamWriter("C:\temp\salida_encoding.txt", True, System.Text.Encoding.Default)
// StreamWriter file = new StreamWriter(AppSettings.Instance.Dpath + "\\notaventa.txt", true, System.Text.Encoding.ASCII);
but none work for print 但没有一个适合打印
canción 坎西翁
everyone print 大家打印
canci?n 坎西
how can i fix it? 我该如何解决? i am using 我在用
compact framework 3.5 紧凑框架3.5
for Hand helds 手持式
You can fix it by not specifying Encoding.ASCII
. 您可以通过不指定Encoding.ASCII
来修复它。 UTF-8 is usually a good bet, although of course it depends on what's going to read the file. UTF-8通常是一个不错的选择,尽管它当然取决于要读取文件的内容。 Basically ASCII doesn't have any accented characters; 基本上ASCII没有任何带重音的字符。 it stops at U+007E. 它停在U + 007E。
I'd expect Encoding.GetEncoding(1252)
to work though, as Windows 1252 contains character "ó". 我希望Encoding.GetEncoding(1252)
能够正常工作,因为Windows 1252包含字符“ó”。 Ditto the default when you don't specify an encoding, as that would use UTF-8. 当您不指定编码时,也与默认值相同,因为它将使用UTF-8。 Are you sure your string contains the right data to start with? 您确定您的字符串包含正确的开头数据吗? What are you using to read the file, too? 您还用什么来读取文件?
ASCII does not include support for the ó
character. ASCII不包括对ó
字符的支持。 Unless you have compelling reason otherwise, you should always use Unicode: 除非您有其他令人信服的理由,否则应始终使用Unicode:
System.IO.StreamWriter file = new System.IO.StreamWriter(
Path.Combine(AppSettings.Instance.Dpath, "notaventa.txt"), true,
System.Text.Encoding.UTF8);
Unrelated to your question: You should use Path.Combine
(rather than explicit string concatenation) for constructing file paths. 与您的问题无关:您应使用Path.Combine
(而不是显式字符串串联)来构造文件路径。 It would save you the headache of determining whether to include the leading/trailing \\
or not. 这将使您省去确定是否包含前导/后缀\\
的麻烦。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.