Write a C# Sharp program to convert the first character of each word of a given string to uppercase

  • برمجة سي شارب
  • برمجة

Write a C# Sharp program to convert the first character of each word of a given string to uppercase. 

Expected 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

الأجوبة

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)));
        }
    }
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...