using System.Collections.Generic;
public static class GetUpperCaseWordsFromString
public static void Main(string[] args)
Console.Write("Input the string : ");
var input = Console.ReadLine();
Console.Write("\nThe UPPER CASE words are :\n ");
foreach (string word in input.SelectWords().WhereIsUppercase())
Console.WriteLine(word.RemoveTrailingPunctuation());
static IEnumerable<string> SelectWords(this string s, bool ignoreDoubleWhiteSpace = false)
for (var current = 0; current < s.Length; current++)
if (char.IsWhiteSpace(s[current]))
var word = s.Substring(start, current - start);
if (!ignoreDoubleWhiteSpace) yield return word;
else if ( word.Length > 1 || (word.Length == 1 && !char.IsWhiteSpace(word[0]))) yield return word;
if (start < s.Length) yield return s.Substring(start, s.Length - start);
static IEnumerable<string> WhereIsUppercase(this IEnumerable<string> seq)
if (s.All(x=> char.IsLetter(x) && char.IsUpper(x) || !char.IsLetter(x))) yield return s;
static string RemoveTrailingPunctuation(this string word)
return word.Length > 0 && char.IsPunctuation(word[word.Length - 1]) ? word.Substring(0, word.Length - 1) : word;