Advertisement
Razhagal

Longest Word in Text

Mar 31st, 2014
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. class LongestWord
  8. {
  9.     static void Main()
  10.     {
  11.         string someText = Console.ReadLine();
  12.         string[] allWords = someText.Split(new char[] { ' ', ',', ':', ';', '.' },
  13.                                                 StringSplitOptions.RemoveEmptyEntries);
  14.  
  15.         int longestWordIndex = 0;
  16.         for (int i = 1; i < allWords.Length; i++)
  17.         {
  18.             if (allWords[i].Length > allWords[longestWordIndex].Length)
  19.             {
  20.                 longestWordIndex = i;
  21.             }
  22.         }
  23.  
  24.         Console.WriteLine(allWords[longestWordIndex]);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement