[英]HOW TO SElect line number in TextBox Multiline
我在我的表單(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'
ERRORenlínea2:
ORA-00904:“”LAVECODIGO“”:識別沒有v?lido
INSERT INTO COM_CODIGOS
ERRORenlínea1:
ORA-00001:restrictciónúnica(XACO.INX_COM_CODIGOS_PK)violada“;
********更多文字************
關於它的任何示例代碼?
您可能希望查看TextBoxBase.GetLineFromCharIndex方法。 此方法檢索文本框中字符位置的行號。
string str = textBox2.Text;
int index = textBox1.Text.IndexOf(str);
if (index !=-1)
{
int lineNo = textBox1.GetLineFromCharIndex(index);
}
“此方法使您能夠根據方法的index參數中指定的字符索引確定行號。控件中的第一行文本返回值零.GetLineFromCharIndex方法返回索引字符所在的物理行號位於控制范圍內。“
編輯:這只查找搜索文本的出現次數。 要計算行數,請使用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);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.