당신은 당신을 발견 문자 위치, 또는 줄 번호 (기억이 안나요) 중 하나를 제공 정규식 패턴을 통해 파일을 검색 할 수 있습니다. 그런 다음 RegEx에서 반환되는 부분을 가져올 수 있습니다.
여기에 내가 그 정규식을 사용하여 쓴 내 자신의 "찾기 및 바꾸기"프로그램에서 코드 블록입니다. ...이 일부 중첩 방법은,하지만 당신은 요점을 파악
int foundInThisFile;
string regExPattern = FindText;
System.Text.RegularExpressions.Regex regSearch = null;
if (IgnoreCase)
regSearch = new System.Text.RegularExpressions.Regex(regExPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Multiline);
else
regSearch = new System.Text.RegularExpressions.Regex(regExPattern, System.Text.RegularExpressions.RegexOptions.Multiline);
System.Text.RegularExpressions.MatchCollection regExMatches = regSearch.Matches(reader.ReadToEnd());
if (reader != null)
{
reader.Dispose();
reader = null;
}
found += regExMatches.Count;
TotalMatches(new CountEventArgs(found));
foundInThisFile = regExMatches.Count;
MatchesInThisFile(new CountEventArgs(foundInThisFile));
if (regExMatches.Count > 0)
{
foreach (System.Text.RegularExpressions.Match match in regExMatches)
{
// The first "group" is going to be the entire regex match, any other "group" is going to be the %1, %2 values that are returned
// Index is the character position in the entire document
if (match.Groups.Count > 1)
{
// This means the user wants to see the grouping results
string[] groupsArray = new string[match.Groups.Count - 1];
for (int counter = 1; counter < match.Groups.Count; counter++)
groupsArray[counter - 1] = match.Groups[counter].Value;
int lineNumber = 0;
string actualLine = String.Empty;
GetLineNumberAndLine(localPath, match.Groups[0].Index, out lineNumber, out actualLine);
AddToSearchResults(localPath, lineNumber, actualLine, groupsArray);
NewSearchResult(new SearchResultArgs(new FindReplaceItem(localPath, lineNumber, actualLine, ConvertGroupsArrayToString(groupsArray))));
}
else
{
int lineNumber = 0;
string actualLine = String.Empty;
GetLineNumberAndLine(localPath, match.Groups[0].Index, out lineNumber, out actualLine);
AddToSearchResults(localPath, lineNumber, actualLine);
NewSearchResult(new SearchResultArgs(new FindReplaceItem(localPath, lineNumber, actualLine)));
}
}
}
우리는 입력의 예를 볼 수 있다면 도움이 될, 그리고 예상되는 출력의 예는 – musefan
그것은 보지 않고 대답을 공식화하는 것은 매우 어렵다 파일의 예입니다. –