I have a richTextbox which some texts inside. Currently, the “orange” is located in the line 3….so how can i get the line of “orange”. My code doesn’t work =(

My C# code:
private void button1_Click(object sender, EventArgs e)
{
string orange = "orange";
int a = richTextBox1.Text.IndexOf(orange);
var b = richTextBox1.Lines.ElementAt(a);
textBox1.Text = b.ToString();
}
How about
Refer to the documentation of RichTextBox.GetLineFromCharIndex(int) and RichTextBox.Find(string)
Basically
Find(string)returns the index of the beginning of the string in the text (or-1if the string wasn’t found), this index is passed toGetLineFromCharIndex(int)which in turn retrieves the line number of the specified index.You may have to handle the special case where your string was not found and
-1was returned fromFind(string).