【问题标题】:HOW TO SElect line number in TextBox Multiline如何在 TextBox Multiline 中选择行号
【发布时间】:2011-02-26 16:31:06
【问题描述】:

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

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

样品,

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

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

版权所有 (c) 1982、2005、甲骨文。保留所有权利。

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

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

WHERE LAVECODIGO = 'CO_PREANUL'

第 2 行错误:

ORA-00904: ""LAVECODIGO"": identificador no v?lido

INSERT INTO COM_CODIGOS

第 1 行错误:

ORA-00001:restrictción única (XACO.INX_COM_CODIGOS_PK) violada";

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

有关于它的示例代码吗?

【问题讨论】:

    标签: c# sql oracle ora-00904 ora-00001


    【解决方案1】:

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

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

    "此方法使您可以根据方法的 index 参数中指定的字符索引确定行号。控件中的第一行文本返回值零。GetLineFromCharIndex 方法返回物理行号,其中索引字符位于控件内。”

    【讨论】:

      【解决方案2】:

      编辑:这只会找到搜索文本的出现。要计算行号,请使用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);
         }
       }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-01-07
        • 2011-11-10
        • 1970-01-01
        • 1970-01-01
        • 2012-10-26
        • 2017-07-11
        相关资源
        最近更新 更多