HOW TO CHANGE Row Number in TextBox Multiline

I have a lot of text in the System.Windows.Forms.TextBox control in my form (winforms), compared to 2008.

I want to find the text and select the line number where I found this text.

Sample,

I have bold large text and I find "ERROR en línea" and I want to select the line number in a multi-line text box.

string textoLogDeFuenteSQL = @"SQL*Plus: Release 10.1.0.4.2 - Production on Mar Jun 1 14:35:43 2010

Copyright (c) 1982, 2005, Oracle. All rights reserved.

******** MORE TEXT ************

Conectado a: Oracle Database 10g Enterprise Edition, release 10.2.0.4.0 - 64-bit production with options for separation, data analysis and testing of real applications

WHERE LAVECODIGO = 'CO_PREANUL'

ERROR en línea 2:

ORA-00904: "" LAVECODIGO "": identifier not specified

INSERT INTO COM_CODIGOS

ERROR en línea 1:

ORA-00001: game restriction (XACO.INX_COM_CODIGOS_PK) viadol ";

******** MORE TEXT ************

?

+3
2

, TextBoxBase.GetLineFromCharIndex. .

string str = textBox2.Text;

            int index = textBox1.Text.IndexOf(str);

            if (index !=-1)
            {                

              int  lineNo = textBox1.GetLineFromCharIndex(index);
            }

" , . 0. GetLineFromCharIndex , ."

+4

:. . , Fredrik .

 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);
   }
 }
+1

Source: https://habr.com/ru/post/1748099/


All Articles