C# Sharp Exercises: Convert the first character of each word of a given string to uppercase
C# Sharp String: Exercise-52 with Solution
Write a C# Sharp program to convert the first character of each word of a given string to uppercase.
Letter case is the distinction between the letters that are in larger uppercase or capitals and smaller lowercase in the written representation of certain languages.
Sample Solution:-
C# Sharp Code:
using System;
using System.Linq;
namespace exercises
{
class Program
{
static void Main(string[] args)
{
string str1 = "python exercises";
Console.WriteLine("Original string: " + str1);
Console.WriteLine("After converting the first character of each word of the said string:\n" + test(str1));
str1 = "The quick brown Fox jumps over the little lazy Dog";
Console.WriteLine("\nOriginal string: " + str1);
Console.WriteLine("After converting the first character of each word of the said string:\n" + test(str1));
}
public static string test(string str1)
{
return string.Join(" ", str1.Split(' ').Select(str1 => char.ToUpper(str1[0]) + str1.Substring(1)));
}
}
}
Sample Output:
Original string: python exercises After converting the first character of each word of the said string: Python Exercises Original string: The quick brown Fox jumps over the little lazy Dog After converting the first character of each word of the said string: The Quick Brown Fox Jumps Over The Little Lazy Dog
Flowchart :
C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
Previous:Write a C# Sharp program to check whether a given string is an "isograms" or not. Return True or False.
Next: Write a C# Sharp program to find the position of a specified word in a given string.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework