stchorbadzhiev

7.Capitalize Words-Strings and Text Processing-Exercises

Jul 30th, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _07.Capitalize_Words
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = Console.ReadLine();
  14.             while (input!="end")
  15.             {
  16.                 char[] delimiters = ".,;:?!- ".ToCharArray();
  17.                 string[] words = input.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
  18.                 string[] capitalizedWords = new string[words.Length];
  19.                 for (int i = 0; i < words.Length; i++)
  20.                 {
  21.                     StringBuilder capitalize = new StringBuilder(words[i].ToLower());
  22.                     capitalize = capitalize.Replace(capitalize[0].ToString(), words[i][0].ToString().ToUpper());
  23.                     capitalizedWords[i] = capitalize.ToString();
  24.                 }
  25.                 Console.WriteLine(string.Join(", ", capitalizedWords));                
  26.                 input = Console.ReadLine();
  27.             }
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment