【问题标题】:Read value from List<List<Word>>从 List<List<Word>> 中读取值
【发布时间】:2015-02-12 16:30:29
【问题描述】:

我的 C# 项目中有以下代码:

List<List<Word>> RecognizedPlates = 
DetectLicensePlate(img, licensePlateImagesList, filteredLicensePlateImagesList, licenseBoxList);
foreach (List<Word> W in RecognizedPlates)
{
     richTextBox1.Text = W.ToString();
}

谁能帮忙阅读List&lt;List&lt;Word&gt;&gt; RecognizedPlates的文字 执行此代码后,我在richTextBox 中什么也没有。

【问题讨论】:

  • Word 是什么?此外,由于您进行了 foreach,因此只有最后一个 Word 会出现在最后的 richTextBox1 文本中。你想达到什么目的?
  • "执行此代码后,我在richTextBox 中什么也没有得到。",请确保您正在获取列表中的一些数据,否则您最终应该得到类似System.Collections.Generic.List``1[Word]另一个问题.
  • @Christos Word 来自 Tessnet2.Word,我正在尝试从“RecognizedPlates”中读取全部内容

标签: c# list tessnet2


【解决方案1】:

如果您想从包含单词列表的列表中创建一个大字符串,请使用string.Join,如下所示:

richTextBox1.Text = string.Join("\n", RecognizedPlates.Select(list =>
    string.Join(" ", list)
));

这将生成一个字符串,其中单个列表的内容由空格连接,由'\n' 字符分隔。例如,像这样的列表列表

{{"quick", "brown"}, {"fox", "jumps", "over"}, {"the", "lazy", "dog"}}

将转换为:

quick brown
fox jumps over
the lazy dog

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    • 1970-01-01
    • 2020-06-12
    • 1970-01-01
    • 2018-03-30
    • 2013-09-09
    相关资源
    最近更新 更多