Advertisement
YavorGrancharov

Value_of_a_String(text_process)

Aug 4th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Value_of_a_String
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string input = Console.ReadLine();
  10.             string command = Console.ReadLine().ToUpper();
  11.  
  12.             var chars = string.Join(string.Empty, input).ToCharArray();
  13.  
  14.             int sum = 0;
  15.             for (int i = 0; i < chars.Length; i++)
  16.             {
  17.                 if (command == "UPPERCASE")
  18.                 {
  19.                     if (char.IsLetter(chars[i]) && char.IsUpper(chars[i]))
  20.                     {
  21.                         sum += chars[i];
  22.                     }
  23.                 }
  24.                 else if (command == "LOWERCASE")
  25.                 {
  26.                     if (char.IsLetter(chars[i]) && char.IsLower(chars[i]))
  27.                     {
  28.                         sum += chars[i];
  29.                     }
  30.                 }
  31.             }
  32.             Console.WriteLine("The total sum is: {0}", sum);
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement