【发布时间】:2014-02-24 11:42:46
【问题描述】:
我读入一个 .csv 文件。
内容如下:
1;"final60";"英国";"2013-12-06 15:48:16";
2;"donnyr8";"荷兰";"2013-12-06 15:54:32";等等
目前我只是尝试使用Replace 方法从每一行中删除引号。这是我尝试过的,似乎没有做任何事情。虽然无论如何似乎都没有破坏程序。
try
{
string item2;
List<string> list = File.ReadLines("file.csv").ToList();
foreach (string listLine in list)
{
Console.Write("# ");
// seperate up this line into a new list by ;
List<string> listItems = listLine.Split(';').ToList();
foreach(String item in listItems)
{
if (item == """)
{
item2 = item.Replace(""", "");
}
else
{
item2 = item;
}
Console.Write(item2);
}
Console.WriteLine("\n");
}
}
catch (Exception e)
{
// Let the user know what went wrong.
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Message);
}
如何去掉每行的引号?
【问题讨论】:
-
您正在寻找 7 个字符的 string
&quot;是文件中的实际内容吗?它是一个 HTML 实体,在 C# 中没有任何意义,使用"\""替换基本的双引号。