HOW TO SElect line number in TextBox Multiline HOW TO SElect line number in TextBox Multiline oracle oracle

HOW TO SElect line number in TextBox Multiline


You might want to look at TextBoxBase.GetLineFromCharIndex method. This method retrieves the line number of character position within the textbox.

string str = textBox2.Text;            int index = textBox1.Text.IndexOf(str);            if (index !=-1)            {                              int  lineNo = textBox1.GetLineFromCharIndex(index);            }

"This method enables you to determine the line number based on the character index specified in the index parameter of the method. The first line of text in the control returns the value zero. The GetLineFromCharIndex method returns the physical line number where the indexed character is located within the control."


EDIT: This only finds the occurrences of the searched text. To compute the line numbers use Fredrik's answer.

 using System.Text.RegularExpressions; public static void FindErrorInText(string input) {   Regex rgx = new Regex("ERROR en linea \d*", RegexOptions.IgnoreCase);   MatchCollection matches = rgx.Matches(input);   if (matches.Count > 0)   {     Console.WriteLine("{0} ({1} matches):", input, matches.Count);     foreach (Match match in matches)        Console.WriteLine("   " + match.Value);   } }