C# 文本正在转换为符号

C# 文本正在转换为符号,c#,visual-studio-2010,C#,Visual Studio 2010,我正在制作一个adz收集器,所以我从一个网站上获取广告,然后获取html,获取标题、价格、描述。最后继续输入数据表,将数据表导出到CSV。但问题是代码中的文本很好,但当其导出到CSV时,类似: · 75% of the Controller’s time will focus on accounting: Their role includes: o Bookkeeping o Payroll o Monthly HST o Trust accounting; Ensurin

我正在制作一个adz收集器,所以我从一个网站上获取广告,然后获取html,获取标题、价格、描述。最后继续输入数据表,将数据表导出到CSV。但问题是代码中的文本很好,但当其导出到CSV时,类似:

 · 75% of the Controller’s time will focus on accounting: Their role includes:  o 
 Bookkeeping  o Payroll  o Monthly HST  o Trust accounting; Ensuring compliance with the     Real 
 Estate Council requirements  o Financial Statement Preparation  · 25% Will be       management 
 functions:  o Supervise and assist with conveyancing  o Supervise all the office staff (4 - 
 6)  o Other day to day management functions.   Requirements and Qualifications  Essential 
 Skills   · Experience working with government regulated financial reporting  · Experience 
 working with large numbers of people in a customer service oriented role  ·     Experience with 
 Trust Accounting    Additional Assets ....
到处都有符号,我用来导出的代码如下:

public  void DataTable2CSV(DataTable table, string filename, string seperateChar)
    {

        StreamWriter sr = null;

        try
        {

            sr = new StreamWriter(filename, true);
            string seperator = "";
            StringBuilder builder = new StringBuilder();


                foreach (DataColumn col in table.Columns)
                {

                    builder.Append(seperator).Append(col.ColumnName);

                    seperator = seperateChar;
                }

                sr.WriteLine(builder.ToString());


            foreach (DataRow row in table.Rows)
            {

                seperator = "";
                builder = new StringBuilder();
                foreach (DataColumn col in table.Columns)
                {

                    builder.Append(seperator).Append(row[col.ColumnName]);
                    seperator = seperateChar;

                }

                sr.WriteLine(builder.ToString());

            }

        }

        finally
        {

            if (sr != null)
            {

                sr.Close();

            }

        }

    } 

您有文本编码混乱。换句话说,您正在写入CSV文件的数据编码与CSV查看器(例如Excel)预期的编码不匹配

有关更多详细信息,请参阅

特别是€™ 例如,这是使用UTF-8读取的Unicode字符“右SINQLE引号”(U+2019)的典型CP1252表示形式。在UTF-8中,该字符存在于字节0xE2、0x80和0x99中。如果您检查CP1252代码页布局,那么您将看到这些字节正好代表字符、€和™.


最可能的原因可能是您的系统中有一种字体,CSV无法支持。查看本文以获取编码帮助

问题是+1。我使用CharacterSet=659001导入CSV。