Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- using System.IO;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace TFYA_lab18
- {
- class Program
- {
- static void Main(string[] args)
- {
- string text = "";
- string[] randWords = new string[] { "program", "new", "old", "strong", "weak", "powerful", "music" };
- using (StreamReader sr = new StreamReader(@"D:\Нужное\ТФЯ\lab18\var5.txt", Encoding.UTF8))
- {
- text = sr.ReadToEnd();
- }
- Console.WriteLine("Введите слово для поиска");
- string search = Console.ReadLine();
- MatchCollection matches = Regex.Matches(text, search);
- Random r = new Random();
- text = Regex.Replace(text, search, randWords[r.Next(0, 7)]);
- Console.WriteLine($"Количество совпадений с заданным словом - {matches.Count}\nСтрока с заменами:\n{text}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement