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


Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. class LinqExercise
  6. {
  7. static void Main(string[] args)
  8. {
  9. string str;
  10. Console.Write("Input the string : ");
  11. str = Console.ReadLine();
  12.  
  13. var ucWord = WordFilt(str);
  14. Console.Write("\nThe upper case words are :\n ");
  15. foreach (string strRet in ucWord)
  16. {
  17. Console.WriteLine(strRet);
  18. }
  19. Console.ReadLine();
  20. }
  21.  
  22. static IEnumerable<string> WordFilt(string mystr)
  23. {
  24. var upWord = mystr.Split(' ')
  25. .Where(x => String.Equals(x, x.ToUpper(),
  26. StringComparison.Ordinal));
  27.  
  28. return upWord;
  29.  
  30. }
  31. }

Result

C# language techstudy.org

     





Related Topics




Popular Posts