问题描述
我已经将导出的文档从outlook转换为CSV,将用于由C#解释进一步操作。使用时出现此问题:
I have been converting an exported document from outlook to CSV which will be used to be interpreted by C# for further manipulations. The problem arises when using:
string path = @"Contacts.csv";
Program Self = new Program();
// Open the file to read from.
var ReadLine = File.ReadLines(path);
foreach (string Line in ReadLine)
{
Console.WriteLine(Line);
Console.ReadKey(true);
}
显示以下数据:
>
这不是期望的输出,并且在击中一个键以传递 ReadKey
之后,其余数据显示为:
(删除联系人号码)
Which is not expected output, and after hitting a key to pass the ReadKey
the rest of the data is displayed with the following: (Blanked out contact Numbers)
不包含换行符(使用CTRL + J替换函数来模拟换行符并且不使用任何内容)。 CSV看起来像:
When the CSV it's self does not contain line breaks (used replace function using CTRL+J to mimic line break and replace with nothing). The CSV Looks like:
没有换行符,这个问题在整个文档中仍然存在,但在其他迭代中不会出现。所以为什么有新的换行符被添加和推到另一个迭代,所以为什么这会出现?
There are no line breaks present, this problem persists throughout the document on some iterations but not others. So why is there new line breaks being added and being pushed to another iteration, so why is this occouring? I've exhausted possibilities which are within my skillset
我试图强制删除换行符
string ToPrint = Line.Replace("\n"," ");
Console.WriteLine(ToPrint);
Console.WriteLine("\r\n");
Console.ReadKey(true);
这会返回相同的结果&将会主动尝试其他可能的解决方案,并用已尝试的内容进行更新
Which returns the same result & will be actively trying out other possible solutions and updating with what's been tried
推荐答案
使用Notepad ++打开CSV文件并将其配置为显示空格字符。你会发现一些东西。也许这个文件只有很多空格。它们在控制台上显示为黑色。也许这行刚包好了。
Open the CSV file with Notepad++ and configure it to display white-space characters. You'll find something. Maybe the file just has very many spaces. They are displayed on the console as black. Maybe the line just wrapped.
您的代码很好。没有明显的错误。并且 ReadLines
和 WriteLine
都无效。
Your code is fine. No obvious mistakes. And neither ReadLines
nor WriteLine
are broken.
这篇关于File.ReadLine为CSV添加换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!