This kind of task is well suited to `Linq` and functional programming, imperative code will only reinvent basic algorithms, so following @Topin suggestion, I suggest this outline: public static string[] words(string text) { // Use of Regex and Splt } public static string longestWord(string text) { // Make use of words and OrderBy }