Created
June 11, 2020 14:43
-
-
Save grishace/f904c0b7a6c96ed8acd3e5354877b7f3 to your computer and use it in GitHub Desktop.
Coderbyte - longest word
This file contains 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
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