Search code examples
c#string-interpolation

C# Create Acronym from Word


Given any string, I'd like to create an intelligent acronym that represents the string. If any of you have used JIRA, they accomplish this pretty well.

For example, given the word: Phoenix it would generate PHX or given the word Privacy Event Management it would create PEM.

I've got some code that will accomplish the latter:

 string.Join(string.Empty, model.Name
                .Where(char.IsLetter)
                .Where(char.IsUpper))

This case doesn't handle if there is only one word and its lower case either.

but it doesn't account for the first case. Any ideas? I'm using C# 4.5


Solution

  • I was able to extract out the JIRA key generator and posted it here. pretty interesting, and even though its JavaScript it could easily be converted to c#.