我的for循环不会将所有信息存储在列表中

时间:2015-08-13 03:22:40

标签: c# list pdf for-loop file-io

我正在尝试阅读200页的pdf文件。数据格式类似excel,我想将每一行添加到列表中。

我目前拥有的for循环只存储当前页面的行。

string[] words2 = null;                
string CurrentPage = " ";

for (int page = 1; page <= reader.NumberOfPages; page++)
{
    CurrentPage = PdfTextExtractor.GetTextFromPage(reader, page);
    //here split the all data of the page in the form of line and store in the string array
    words2 = CurrentPage.Split('\n');
    words2.ToList();

}

如何将10,000行文本添加到同一列表中?

1 个答案:

答案 0 :(得分:1)

List<string> words2 = new List<string>();                
string CurrentPage = null;
        for (int page = 1; page <= reader.NumberOfPages; page++)
        {
            CurrentPage = PdfTextExtractor.GetTextFromPage(reader, page);
           //here split the all data of the page in the form of line and store in the string array

            words2.AddRange(CurrentPage.Split('\n'));
        }` 
//if you want an array at the end.
string[] words3 = words2.ToArray();

你还有什么期待吗?