Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp Exercises: Find the uppercase words in a string

C# Sharp LINQ : Exercise-12 with Solution

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

Sample Solution:-

C# Sharp Code:

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;

		}
	}
	

Sample Output:

LINQ : Find the uppercase words in a string :                       
----------------------------------------------                      
Input the string : this IS a STRING                                 
                                                                    
The UPPER CASE words are :                                          
 IS                                                                 
STRING

Pictorial Presentation:

C# Sharp LINQ: Find the uppercase words in a string.

Flowchart:

Flowchart: LINQ : Find the uppercase words in a string

C# Sharp Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a program in C# Sharp to display the top nth records.
Next: Write a program in C# Sharp to convert a string array to a string.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.