Skip to content

Instantly share code, notes, and snippets.

@umaqs
Created June 3, 2019 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save umaqs/2f70f4bbf920b25bad32c9ba62d8b6cf to your computer and use it in GitHub Desktop.
Save umaqs/2f70f4bbf920b25bad32c9ba62d8b6cf to your computer and use it in GitHub Desktop.
A small program to filter words
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