SHARE
TWEET

18

a guest Dec 8th, 2019 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.IO;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace TFYA_lab18
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             string text = "";
  16.             string[] randWords = new string[] { "program", "new", "old", "strong", "weak", "powerful", "music" };
  17.             using (StreamReader sr = new StreamReader(@"D:\Нужное\ТФЯ\lab18\var5.txt", Encoding.UTF8))
  18.             {
  19.                 text = sr.ReadToEnd();
  20.             }
  21.             Console.WriteLine("Введите слово для поиска");
  22.             string search = Console.ReadLine();
  23.             MatchCollection matches = Regex.Matches(text, search);
  24.             Random r = new Random();
  25.             text = Regex.Replace(text, search, randWords[r.Next(0, 7)]);
  26.             Console.WriteLine($"Количество совпадений с заданным словом - {matches.Count}\nСтрока с заменами:\n{text}");
  27.         }
  28.     }
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top