我遇到一个csv文件中的字符问题,通过黑钻与一个?在中间。适应csv阅读器读取unicode字符
我已经编写了解析csv的代码,但我不明白为什么字符串没有正确读取unicode字符。这可能与我的实现有关:
StreamReader readFile = new StreamReader(path)
try {
while ((line = readFile.ReadLine()) != null) {
string[] row = { "", "", "" };
int currentItem = 0;
bool inQuotes = false;
if (skippedFirst && currentItem != 3) {
for (int i = 0; i < line.Length; i++) {
if (!inQuotes) {
if (line[i] == '\"')
inQuotes = true;
else {
if (line[i] == ',')
currentItem++;
else
row[currentItem] += line[i];
}
} else {
if (line[i] == '\"')
inQuotes = false;
else
row[currentItem] += line[i];
}
}
parsedFile.Add(row);
}
skippedFirst = true;
}
如果'readFile'是'StreamReader',你可以使用与编码部分的构造:'Encoding.UTF8 '。 –
显示'readFile'的创建。 – leppie
@ Trustme-I'maDoctor把它作为答案!这有助于出色 – ediblecode