Created
June 3, 2019 00:06
-
-
Save umaqs/2f70f4bbf920b25bad32c9ba62d8b6cf to your computer and use it in GitHub Desktop.
A small program to filter words
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Linq; | |
using System.Collections.Generic; | |
using System.Text.RegularExpressions; | |
namespace FilterWords | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
if (args == null || args.Length == 0) | |
{ | |
Console.WriteLine("Please provide a path argument"); | |
return; | |
} | |
try | |
{ | |
string path = args[0]; | |
Regex regex = new Regex(@"^[a-zA-Z]+$"); | |
var text = File.ReadAllText(path); | |
var words = text.Split('\n').ToList(); | |
words = words.Where(w => w.Length >= 3 && regex.Match(w).Success).Select(w => w.ToLower()).Distinct().OrderBy(s => s).ToList(); | |
File.WriteAllText(path, String.Join('\n', words)); | |
} | |
catch (xception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment