Advertisement
Aborigenius

ASCIIValueOfAString

Aug 22nd, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ASCiiValueOfAString
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string text = Console.ReadLine();
  15.             string command = Console.ReadLine();
  16.             int sum = 0;
  17.             if (command == "UPPERCASE")
  18.             {
  19.                 char[] up = text.Where(c => char.IsUpper(c)).ToArray();
  20.                 byte[] asciiValues = Encoding.ASCII.GetBytes(up);
  21.  
  22.                 foreach (var c in asciiValues)
  23.                 {
  24.                     sum += c;
  25.                 }
  26.             }
  27.             else if (command == "LOWERCASE")
  28.             {
  29.                 char[] low = text.Where(c => char.IsLower(c)).ToArray();
  30.                 byte[] asciiValues = Encoding.ASCII.GetBytes(low);
  31.                 foreach (var c in asciiValues)
  32.                 {
  33.                     sum += c;
  34.                 }
  35.             }
  36.  
  37.             Console.WriteLine($"The total sum is: {sum}");
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement