简体   繁体   中英

Saving Specific line of richTextBox in a Variable C#

Using this code i get the line of characters which I want to store in a variable

string find = textBox1.Text;
string lineText = null;
int lineNum = richTextBox1.GetLineFromCharIndex(richTextBox1.Find(find));
MessageBox.Show("Line Number is " + lineNum);

How can I store the resulted line text from richTextBox in string variable.

You can use the Lines[] array:

int charNum = richTextBox1.Find(find);
if (charNum > -1) {
  lineText = richTextBox1.Lines[richTextBox1.GetLineFromCharIndex(charNum)];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM