Skip to content

Instantly share code, notes, and snippets.

@AndrewAllison
Created October 9, 2019 07:59
Show Gist options
  • Save AndrewAllison/fdd8a9cb037ac94ccbb9c8bbd43ffa6c to your computer and use it in GitHub Desktop.
Save AndrewAllison/fdd8a9cb037ac94ccbb9c8bbd43ffa6c to your computer and use it in GitHub Desktop.
Make nice Acronyms out of sentences.
using System;
using System.Linq;
using System.Text.RegularExpressions;
public static class Acronym
{
public static string Abbreviate(string phrase)
{
// Only letters, hyphens and spaces
phrase = new Regex("[^A-Za-z -]").Replace(phrase, "").ToUpperInvariant();
char[] seperator = { ' ', '-' };
return string.Join("", phrase.Split(seperator, StringSplitOptions.RemoveEmptyEntries)
.Select(t => t[0]));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment