Hello, everyone!
I try to write in console only one string, that contains reg text, but my code writes all text from file
Could you help me write my target string in console?
Thanks!
I try to write in console only one string, that contains reg text, but my code writes all text from file
Could you help me write my target string in console?
Thanks!
C#:
[COLOR=#0600FF]using[/COLOR] [COLOR=teal]System[/COLOR][COLOR=green];[/COLOR]
[COLOR=#0600FF]using[/COLOR] [COLOR=teal]System.Collections.Generic[/COLOR][COLOR=green];[/COLOR]
[COLOR=#0600FF]using[/COLOR] [COLOR=teal]System.Linq[/COLOR][COLOR=green];[/COLOR]
[COLOR=#0600FF]using[/COLOR] [COLOR=teal]System.Text[/COLOR][COLOR=green];[/COLOR]
[COLOR=#0600FF]using[/COLOR] [COLOR=teal]System.Threading.Tasks[/COLOR][COLOR=green];[/COLOR]
[COLOR=#0600FF]using[/COLOR] [COLOR=teal]System.IO[/COLOR][COLOR=green];[/COLOR]
[COLOR=#0600FF]using[/COLOR] [COLOR=teal]System.Text.RegularExpressions[/COLOR][COLOR=green];[/COLOR]
[COLOR=#0600FF]namespace[/COLOR] ConsoleApp1
[COLOR=green]{[/COLOR]
[COLOR=#6666CC]class[/COLOR] Program
[COLOR=green]{[/COLOR]
[COLOR=#0600FF]static[/COLOR] [COLOR=#6666CC]void[/COLOR] Main[COLOR=green]([/COLOR][COLOR=#6666CC]string[/COLOR][COLOR=green][[/COLOR][COLOR=green]][/COLOR] args[COLOR=green])[/COLOR]
[COLOR=green]{[/COLOR]
[COLOR=#6666CC]string[/COLOR] rootFolder [COLOR=green]=[/COLOR] [COLOR=#666666]@"H:\Test"[/COLOR][COLOR=green];[/COLOR]
[COLOR=#0600FF]foreach[/COLOR] [COLOR=green]([/COLOR][COLOR=#0600FF]var[/COLOR] file [COLOR=#0600FF]in[/COLOR] Directory[COLOR=green].[/COLOR][COLOR=#0000FF]EnumerateFiles[/COLOR][COLOR=green]([/COLOR]rootFolder, [COLOR=#666666]"*"[/COLOR], SearchOption[COLOR=green].[/COLOR][COLOR=#0000FF]AllDirectories[/COLOR][COLOR=green])[/COLOR][COLOR=green])[/COLOR]
[COLOR=green]{[/COLOR]
[COLOR=teal][I]//File.AppendAllText(file, "Hi, man");[/I][/COLOR]
StreamReader sr [COLOR=green]=[/COLOR] [COLOR=green]new[/COLOR] StreamReader[COLOR=green]([/COLOR]file, Encoding[COLOR=green].[/COLOR][COLOR=#0600FF]Default[/COLOR][COLOR=green])[/COLOR][COLOR=green];[/COLOR]
[COLOR=#6666CC]string[/COLOR] s [COLOR=green]=[/COLOR] sr[COLOR=green].[/COLOR][COLOR=#0000FF]ReadToEnd[/COLOR][COLOR=green]([/COLOR][COLOR=green])[/COLOR][COLOR=green];[/COLOR]
[COLOR=#6666CC]String[/COLOR] pattern [COLOR=green]=[/COLOR] [COLOR=#666666]@"\b(Vasya)\b"[/COLOR][COLOR=green];[/COLOR]
[COLOR=#0600FF]if[/COLOR] [COLOR=green]([/COLOR]Regex[COLOR=green].[/COLOR][COLOR=#0000FF]IsMatch[/COLOR][COLOR=green]([/COLOR]s, pattern, RegexOptions[COLOR=green].[/COLOR][COLOR=#0000FF]IgnoreCase[/COLOR][COLOR=green])[/COLOR][COLOR=green])[/COLOR]
[COLOR=green]{[/COLOR]
Console[COLOR=green].[/COLOR][COLOR=#0000FF]WriteLine[/COLOR][COLOR=green]([/COLOR]s[COLOR=green])[/COLOR][COLOR=green];[/COLOR]
[COLOR=green]}[/COLOR]
sr[COLOR=green].[/COLOR][COLOR=#0000FF]Close[/COLOR][COLOR=green]([/COLOR][COLOR=green])[/COLOR][COLOR=green];[/COLOR]
[COLOR=green]}[/COLOR]
Console[COLOR=green].[/COLOR][COLOR=#0000FF]ReadKey[/COLOR][COLOR=green]([/COLOR][COLOR=green])[/COLOR][COLOR=green];[/COLOR]
[COLOR=green]}[/COLOR]
[COLOR=green]}[/COLOR]
[COLOR=green]}[/COLOR]