Created
March 12, 2017 08:51
-
-
Save Soulstorm50/0bfce54e0acb2f70ed2662672ca9405b to your computer and use it in GitHub Desktop.
C# Search text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. указать путь к директории (например, "C:\\1\\"). указать текст для поиска по файлам (например, "test"). | |
// программа показывает названия всех файлов, которые лежат в указанной директории и содержат указанный текст. | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.IO; | |
using System.Text.RegularExpressions; | |
namespace ConsoleApplication3 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Введите путь к файлу для поиска текста (Например D:\\Soulstorm\\Blacklist.txt)"); | |
string text = File.ReadAllText(Console.ReadLine(), Encoding.GetEncoding(1251)); | |
Console.WriteLine("Введите слово для поиска (Например - Наташа)"); | |
string pattern = Console.ReadLine(); | |
int i = 0; | |
foreach (Match m in Regex.Matches(text, pattern, RegexOptions.IgnoreCase)) | |
i += 1; | |
Console.WriteLine(i); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment