【问题标题】:My for-loop will not store all my info in a list我的 for 循环不会将我的所有信息存储在列表中
【发布时间】:2015-08-13 03:22:39
【问题描述】:

我正在尝试阅读 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 行文本添加到同一个列表中?

【问题讨论】:

  • 在调用words2.ToList()之后,你需要将它分配给一些东西。

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


【解决方案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();

您还有什么期待的吗?

【讨论】:

  • 如果这是您正在寻找的答案,请将其标记为一个,以便对其他人有所帮助
猜你喜欢
  • 2013-03-21
  • 2017-07-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-20
  • 2020-10-03
相关资源
最近更新 更多