写入文件时进行编码的通用解决方案 [英] Generic solution for encoding when writing to a file

查看:96
本文介绍了写入文件时进行编码的通用解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一种将数据导出到文件(.txt或.csv)的方法。一切正常,除了编码。



导出的数据包含诸如(é,à,...)等字符,这些caractere在同一台计算机上显示不正确其他的很好。



这里是代码。

Hi all,
I have a method that export data to a file(.txt or .csv). all works fine except the encoding.

the exported data contains caracters such as (é, à,...), those caractere appears incorrectly in same computers while it works fine in others.

here is the code.

using (StreamWriter sWriter = new StreamWriter(stream, Encoding.UTF8))
{
   sWriter.WriteLine("Nom ; Prénom ; Adresse ; Code postal ; Ville ; Prospection ; Fixe1 ; Fixe2 ; Fax ; Portable");

   foreach (ExtendedContact c in extendedContactList)
   {
      if (cb_prospection.Checked)
      {
         if (c.Prospection != "Contre")
         {
            sWriter.Write(OneSpace(c.Nom) + ";" + OneSpace(c.Prenom) + ";" + OneSpace(c.Address) + ";" + OneSpace(c.CodePostal) + ";" + OneSpace(c.Ville) + ";" + OneSpace(c.Prospection) + ";" + OneSpace(c.Fixe1) + ";" + OneSpace(c.Fixe2) + ";" + OneSpace(c.Fax) + ";" + OneSpace(c.Portable));
            sWriter.WriteLine();
         }
      }
   }
}





我想创建一个通用解决方案适用于任何计算机。

您认为最好的解决方案是什么?我是否必须让用户在不同类型的编码之间进行选择(因为许多用户不知道编码是什么,所以我完全是aginst)?



谢谢



I want to create a generic solution that works in any computer.
what do you think is the best solution? do i have to give the user to select between diffrent kind of encoding(i am totaly aginst since many user don't know what encoding is)?

Thanks

推荐答案

这篇关于写入文件时进行编码的通用解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆