c# - 从带有关键字的文本中搜索一行(已解决)并在搜索行之后显示第三行
问题描述
我想在使用文本中的关键字搜索初始行后显示第三行:
我想在文本框中的第三行中分割所有变量。关键字是 [参考 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();
}
}
解决方案
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
}
}
}
推荐阅读
- shell - 在 shell 脚本中捕获 exec 返回代码
- php - PHPMailer 错误:致命错误:未捕获错误:调用未定义的方法 PHPMailer\PHPMailer\PHPMailer::isSTMP()
- c# - C#服务器响应socket.io
- rust - 将 Result 的迭代器转换为 Result
> - angular - Angular 6:返回 HttpHeaders
- canvas - 我可以在 javafx 中创建圆形画布吗?
- python - 创建特定排列 Python
- vuejs2 - VueJS:为什么 v-model 不适用于 vuejs 过滤器
- java - RunOnUiThread 无法直接访问 Message
- java - Java GlazedList 单列过滤