Last active
August 13, 2018 03:11
-
-
Save StrykerKent/b15d10d1a3d75a04badd31b3a89f30d9 to your computer and use it in GitHub Desktop.
Question was "Find the largest word in a sentence." I used C# for this.
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
using System; | |
using System.Linq; | |
using System.Text.RegularExpressions; | |
class MainClass { | |
public static string LongestWord(string sen) { | |
// remove unwanted characters (everything except a-z 0-9 or spaces) | |
sen = Regex.Replace(sen, @"[^a-zA-Z0-9 ]+", "", RegexOptions.Compiled); | |
// split words into array | |
string[] words = sen.Split(' '); | |
// query for 1 word with largest length | |
var final = words.OrderByDescending(s=>s.Length).First(); | |
return final; | |
} | |
static void Main() { | |
Console.WriteLine(LongestWord(Console.ReadLine())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment