Advertisement
didatzi

P04_PunctuationFinder

Jun 28th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace P04_PunctuationFinder
  8. {
  9.     class PunctuationFinder
  10.     {
  11.         static void Main()
  12.         {
  13.             string textFromFile = File.ReadAllText("sample_text.txt");
  14.             Regex regex = new Regex(@"[,\.!?\:]");
  15.             var match = regex.Matches(textFromFile);
  16.             List<string> charList = new List<string>();
  17.             foreach (Match item in match)
  18.             {
  19.                charList.Add(item.Value);
  20.             }
  21.             Console.WriteLine(string.Join(", ", charList));
  22.            
  23.             //String[] input = File.ReadAllLines("sample_text.txt");
  24.             //List<char> punctoationChars = new List<char>();
  25.  
  26.             //char[] punctList = new[] {',', '.', '!', '?', ':'};
  27.             //foreach (string line in input)
  28.             //{
  29.             //    for (int i = 0; i < line.Length; i++)
  30.             //    {
  31.             //        if (punctList.Contains(line[i]))
  32.             //        {
  33.             //            punctoationChars.Add(line[i]);
  34.             //        }
  35.             //    }
  36.             //}
  37.             //Console.Write(string.Join(", ", punctoationChars));
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement