文本正在转换为符号
本文关键字:符号 转换 文本 | 更新日期: 2023-09-27 17:58:49
我正在制作一个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字符"RIGHT SINQLE QUOTETION MARK"(U+2019)的典型CP1252表示。在UTF-8中,该字符存在于字节0xE2、0x80和0x99中。如果您检查CP1252代码页布局,那么您会看到这些字节正好代表字符â、€和™.
最可能的原因可能是您的系统和CSV无法支持字体。查看本文以获取编码帮助。http://office.microsoft.com/en-us/help/choose-text-encoding-when-you-open-and-save-files-HA010121249.aspx