在某个文本后从listbox1中提取文本? [英] Extract text from listbox1 after a certain text ?
本文介绍了在某个文本后从listbox1中提取文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello everyone,
This below is a code that extracts everything from listBox1 after "sometext" in textBox1.text, and it works well.
private void extract()
{
string s = string.Join(Environment.NewLine, listBox1.SelectedItems.OfType<object>().Select(i => Regex.Match(i.ToString(), @"sametext?(.*?)(?=#|$)").Groups[1].Value));
textBox1.Text = (s.ToString());
}
"sometext" is not always the same.
I would like to replace "sametext" with textBox2.text
textBox2.Text = different text
I tried:
我尝试过:
What I have tried:
private void extract()
{
string s = string.Join(Environment.NewLine, listBox1.SelectedItems.OfType<object>().Select(i => Regex.Match(i.ToString(), "@"+ textBox2.Text + "?(.*?)(?=#|$)").Groups[1].Value));
textBox1.Text = (s.ToString());
}
But it does not work.
Please help me.
Thank you.
推荐答案
))。Groups [1] .Value));
textBox1.Text =(s.ToString());
}
sometext并不总是相同。
我会喜欢用textBox2.text替换sametext
textBox2.Text =不同的文字
我试过:
)").Groups[1].Value)); textBox1.Text = (s.ToString()); } "sometext" is not always the same. I would like to replace "sametext" with textBox2.text textBox2.Text = different text I tried:
我尝试过:
What I have tried:
private void extract()
{
string s = string.Join(Environment.NewLine, listBox1.SelectedItems.OfType<object>().Select(i => Regex.Match(i.ToString(), "@"+ textBox2.Text + "?(.*?)(?=#|
))。组[1] .Value));
textBox1.Text =(s.ToString ());
}
但它不起作用。
请帮助我。
谢谢。
)").Groups[1].Value)); textBox1.Text = (s.ToString()); } But it does not work. Please help me. Thank you.
将你的模式放在一个单独的字符串中(在匹配中使用它之前),显示它,并观察为什么它不是什么你期待。
当你没有证据时,你正在做出很多关于哪些TextBox包含什么等的假设。
Put your "pattern" in a separate string (before using it in "Match"), display it, and observe "why" it is not what you expect.
You're making a lot of assumptions about which TextBox contains what, etc. when you have no "proof".
这篇关于在某个文本后从listbox1中提取文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文