Advertisement
ScorpS

Delete Words Start With Test

Jan 28th, 2013
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. //Write a program that deletes from a text file all words that start with the prefix "test".
  2. //Words contain only the symbols 0...9, a...z, A…Z, _.
  3.  
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Text.RegularExpressions;
  9. using System.Threading.Tasks;
  10. using System.IO;
  11.  
  12.  
  13. class DeleteWordsStartWithTest11
  14. {
  15.     static void Main()
  16.     {
  17.         StreamReader read = new StreamReader("../../test.txt");
  18.         StreamWriter write = new StreamWriter("../../output.txt");
  19.         string line = "";
  20.  
  21.         using (read)
  22.         {
  23.             using (write)
  24.             {
  25.                 line = read.ReadLine();
  26.                 while (line != null)
  27.                 {
  28.                     line = line.ToLower();
  29.                     line = Regex.Replace(line, @"\btest\w*(\s|\S)\b", "");
  30.                     write.WriteLine(line);
  31.                     line = read.ReadLine();                      
  32.                 }
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement