Skip to content

Instantly share code, notes, and snippets.

@Soulstorm50
Created March 12, 2017 08:51
Show Gist options
  • Save Soulstorm50/0bfce54e0acb2f70ed2662672ca9405b to your computer and use it in GitHub Desktop.
Save Soulstorm50/0bfce54e0acb2f70ed2662672ca9405b to your computer and use it in GitHub Desktop.
C# Search text
// 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