首页 > 解决方案 > 从带有关键字的文本中搜索一行(已解决)并在搜索行之后显示第三行

问题描述

我想在使用文本中的关键字搜索初始行后显示第三行:

我想在文本框中的第三行中分割所有变量。关键字是 [参考 1]

文本文件

        {  // string motcledm = "code:A14";
            string line;

            string motcletest = SEARCH.Text;

            using (System.IO.StreamReader file = new System.IO.StreamReader(@"D:\\TEST.txt"))
            {
                while ((line = file.ReadLine()) != null)
                {
                    if ((line.Contains(motcletest)))
                    {
                        richTextBox1.Text = line.ToString();
                    }
                }

我需要的输出 输出

标签: c#

解决方案


        string line;

        string motcletest = SEARCH.Text;

        using (System.IO.StreamReader file = new System.IO.StreamReader(@"D:\\TEST.txt"))
        {
            while ((line = file.ReadLine()) != null)
            {
                if ((line.Contains(motcletest)))
                {
                    richTextBox1.Text = line.ToString();
                    file.ReadLine();//read first line after matching line
                    file.ReadLine();//read second line after matching line
                    line = file.ReadLine(); //third line that you are looking for
                    foreach(var value in line.Split(','))//split by ,
                    {
                       //Add the value the controls(textbox)
                       //if the count is not fixed, you might need to create a control and add it to a panel
                    }
                }
            }

推荐阅读