如何在TextBox Multiline中选择行号

问题描述 投票:3回答:2

我在我的表单(winforms)中的System.Windows.Forms.TextBox控件中有大文本,与2008相比。

我想找到一个文本,然后选择我找到该文本的行号。

样品,

我有大文字,我发现“ERRORenlínea”,我想在文本框多行中选择行号。

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

版权所有(c)1982,2005,Oracle。版权所有。

********更多文字************

Conectado a:Oracle数据库10g企业版10.2.0.4.0版 - 64位生产使用分区,数据挖掘和实际应用程序测试选项

WHERE LAVECODIGO = 'CO_PREANUL'

ERROR在线2:

ORA-00904:“”LAVECODIGO“”:标识符无效

INSERT INTO COM_CODIGOS

错误在线1:

ORA-00001:违反单一限制(XACO.INX_COM_CODIGOS_PK)“;

********更多文字************

关于它的任何示例代码?

c# sql oracle ora-00904 ora-00001
2个回答
4
投票

你可能想看看TextBoxBase.GetLineFromCharIndex方法。此方法检索文本框中字符位置的行号。

string str = textBox2.Text;

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

            if (index !=-1)
            {                

              int  lineNo = textBox1.GetLineFromCharIndex(index);
            }

“此方法使您能够根据方法的index参数中指定的字符索引确定行号。控件中的第一行文本返回值零.GetLineFromCharIndex方法返回索引字符所在的物理行号位于控制范围内。“


1
投票

编辑:这只查找搜索文本的出现次数。要计算行数,请使用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);
   }
 }
© www.soinside.com 2019 - 2024. All rights reserved.