[英]How I can search keyword from text file/ sql file in c#.net which are not commented?
我必須從.sql或.txt文件中搜索關鍵字。 這些關鍵字不應該在評論中。
例如,如果我想搜索2個關鍵字,如“set rowcount”和“holdlock”。 我能夠在文件中找到它們。 但根據要求。 這些不應該在評論中。 (不在/ * * /之間或以//開頭)。
任何人都可以給我一個想法。
foreach (string word in words)
{
int s_start = FileDisplayArea.SelectionStart, startIndex = 0, index;
int wordIndex = 0;
while ((index = FileDisplayArea.Text.IndexOf(word, startIndex)) != -1)
{
NoOfOccurance[wordIndex] += 1;
FileDisplayArea.Select(index, word.Length);
FileDisplayArea.SelectionColor = Color.Yellow;
startIndex = index + word.Length;
}
FileDisplayArea.SelectionStart = s_start;
FileDisplayArea.SelectionLength = 0;
FileDisplayArea.SelectionColor = Color.Red;
wordIndex += 1;
}
謝謝你的幫助。 我通過遵循邏輯來解決這個問題
bool commentStarted = false, commentEnds = false; foreach (string line in scriptAllLines) { if (line.Contains("/*")) { commentStarted = true; commentEnds = false; } if (line.Contains("*/")) { commentEnds = true; commentStarted = false; } }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.