所以我这里有这段代码
int pos = richTextBox1.Find("someText", RichTextBoxFinds.MatchCase);
if (pos != -1)
{
int line = richTextBox1.GetLineFromCharIndex(pos);
string lineString = line.ToString();
string inside = string.Format(lineString);
MessageBox.Show(inside);
}
如果您不熟悉,那就是查找特定文本所在的行。
我想取出那行文本并阅读整行是什么。
例如,如果该行是 someText hfdshjslkgjhsdilg
然后我会收到一个消息框,上面写着 someText hfdshjslkgjhsdilg
最佳答案
这是 LINQ 解决方案:
string line = richTextBox.Lines.FirstOrDefault(l => l.Contains(searchedText));
if (line != null) MessageBox.Show(line);
关于c# - 读取富文本框中的特定行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36612453/