【发布时间】:2012-02-09 09:42:19
【问题描述】:
我有这个代码:
string ABSfilePath = "";
CsvFileReader reader = null;
ABSfilePath = Server.MapPath("/myfile.csv");
try
{
reader = new CsvFileReader(ABSfilePath);
CsvRow myRow = new CsvRow();
while (reader.ReadRow(myRow))
{
Response.Write(myRow[0].ToString()+"<br />");
}
}
catch (Exception err)
{
Response.Write(err.Message);
}
finally
{
if (reader != null)
reader.Dispose();
}
但是当我尝试导入我的文件 myfile.csv 时,一些字符被“不正确”编码,例如:
STATUA DELLA LIBERT�
那么,如何编码呢?谢谢
【问题讨论】:
-
您是否 100% 确定在导入之前使用记事本或记事本++ 打开文件会显示正确的字符而不是上面的有趣符号?
-
用记事本++打开我得到了STATUA DELLA LIBERT·
-
如果 char 之前不存在,则文件编码错误,与 CSV 解析无关,而是首先以正确的格式和编码获取文件。
-
但在 CSV 上是 STATUA DELLA LIBERTÀ(这是正确的)
-
...这就是它应该的方式?