简体   繁体   English

.net紧凑框架上的system.io.streamwriter

[英]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.

相关问题 关于System.IO.StreamWriter的问题 - Questions about System.IO.StreamWriter System.IO.StreamWriter不会为整个for循环写入 - System.IO.StreamWriter doesn't write for entire for loop 在C#中快速打开和关闭System.IO.StreamWriter - Rapid Opening and Closing System.IO.StreamWriter in C# 如何修复 StreamWriter 错误“无法将类型字符串隐式转换为 System.IO.StreamWriter” - How to fix StreamWriter error “cannot implicitly convert type string to System.IO.StreamWriter” System.InvalidCastException:无法将类型为“ System.Object”的对象转换为类型为“ System.IO.StreamWriter” - System.InvalidCastException: Unable to cast object of type 'System.Object' to type 'System.IO.StreamWriter' 我的 C# 代码使用 System.IO.StreamWriter 输出一定长度的随机中文/unicode字符 - My C# code using System.IO.StreamWriter outputs random chinese/unicode characters at a certain length 使用带有长字符串 Json 的 System.IO.StreamWriter 的 C# 文件限制 - C# file limit using System.IO.StreamWriter with long string Json 将使用System.IO.StreamWriter和WriteLineAsync等待另一个线程正在访问的文件 - Will using System.IO.StreamWriter & WriteLineAsync wait for a file that is being accessed by another thread 为什么我不能从“System.IO.StreamWriter”转换为“CsvHelper.ISerializer”? - Why can't I convert from 'System.IO.StreamWriter' to 'CsvHelper.ISerializer'? StreamWriter无法在紧凑的.net 2.0中识别c:\\ - StreamWriter fails to recognize c:\ in compact .net 2.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM