Skip to content

Instantly share code, notes, and snippets.

@billpratt
Last active August 29, 2015 14:22
Show Gist options
  • Save billpratt/ea3f0a91734d84c930e4 to your computer and use it in GitHub Desktop.
Save billpratt/ea3f0a91734d84c930e4 to your computer and use it in GitHub Desktop.
Return the most common character that appears first
public static char FirstMostCommonCharacter(string text)
{
return text
.GroupBy(c => c)
.OrderByDescending(c => c.Count())
.Where(c => c.Key != ' ') // dont include white space
.Select(c => c.Key)
.FirstOrDefault();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment