Q:

Write a program in C# Sharp to find the uppercase words in a string

0

 Write a program in C# Sharp to find the uppercase words in a string. 
Test Data :
Input the string : this IS a STRING
Expected Output :
The UPPER CASE words are :
IS
STRING

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
using System.Linq;
using System.Collections.Generic;
 
class LinqExercise12
	{
		static void Main(string[] args)
		{
            Console.Write("\nLINQ : Find the uppercase words in a string : "); 
            Console.Write("\n----------------------------------------------\n");   
            string strNew;   
           Console.Write("Input the string : ");
            strNew= Console.ReadLine();
			var ucWord = WordFilt(strNew);
			Console.Write("\nThe UPPER CASE words are :\n ");
			foreach (string strRet in ucWord)
			{
			Console.WriteLine(strRet);
			}
			Console.ReadLine();
		}
	static IEnumerable<string> WordFilt(string mystr)
		{           
			var upWord =  mystr.Split(' ')
						.Where(x => String.Equals(x, x.ToUpper(),
                        StringComparison.Ordinal));
			return upWord;
		}
	}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now