Created
October 9, 2019 07:59
-
-
Save AndrewAllison/fdd8a9cb037ac94ccbb9c8bbd43ffa6c to your computer and use it in GitHub Desktop.
Make nice Acronyms out of sentences.
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.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