Advertisement
obedmarsh

01. Value of a String

Aug 5th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Extended
  7. {
  8.  
  9.  
  10.     class Program
  11.     {
  12.         static bool IsLetter(string str)
  13.         {
  14.             for (int i = 0; i < str.Length; i++)
  15.             {
  16.                 if ((int)str[i] >= 65 && (int)str[i] <= 90 ||
  17.                     (int)str[i] >= 97 && (int)str[i] <= 122)
  18.                 {
  19.                     return true;
  20.                 }
  21.             }
  22.                 return false;
  23.         }
  24.  
  25.  
  26.         static void Main(string[] args)
  27.         {
  28.             string input = Console.ReadLine();
  29.             string upOrLower = Console.ReadLine();
  30.             List<char> ch = new List<char>();
  31.             ch = input.ToList();
  32.             int sum = 0;
  33.             if (upOrLower == "UPPERCASE")
  34.             {
  35.                 for (int i = 0; i < input.Length; i++)
  36.                 {
  37.                     if (IsLetter(input) && char.IsUpper(input[i]))
  38.                     {
  39.                         sum += (int)input[i];
  40.                     }
  41.                 }
  42.  
  43.             }
  44.             else
  45.             {
  46.                 for (int i = 0; i < input.Length; i++)
  47.                 {
  48.                     if (IsLetter(input) && char.IsLower(input[i]))
  49.                     {
  50.                         sum += (int)input[i];
  51.                     }
  52.                 }
  53.  
  54.             }
  55.  
  56.             Console.WriteLine("The total sum is: {0}", sum);
  57.         }
  58.  
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement