Skip to content

Instantly share code, notes, and snippets.

@grishace
Created June 11, 2020 14:43
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 grishace/f904c0b7a6c96ed8acd3e5354877b7f3 to your computer and use it in GitHub Desktop.
Save grishace/f904c0b7a6c96ed8acd3e5354877b7f3 to your computer and use it in GitHub Desktop.
Coderbyte - longest word
private static readonly Regex rx = new Regex(@"\b(\w+)\b");
public static string LongestWord(string sen) {
return rx.Matches(sen)
.Select(m => m.Groups[0].Value)
.Select(w => Tuple.Create(w, w.Length))
.OrderByDescending(t => t.Item2)
.Select(t => t.Item1)
.FirstOrDefault();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment