SHARE
TWEET

String&Text - 21

geniusvil Jan 4th, 2014 38 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _21.PrintDiferentLetters
  8. {
  9.     class PrintDiferentLetters
  10.     {
  11.         /* Write a program that reads a string from the
  12.          * console and prints all different letters in the
  13.          * string along with information how many times each
  14.          * letter is found.*/
  15.  
  16.         static void Main()
  17.         {
  18.             Console.Write("Please enteyr string : ");
  19.             string inputString = Console.ReadLine().ToLower();
  20.             string letters = "abcdefghijklmnopqrstuvwxyzABCDEFJHIGKLMNOPQRSTUVWXYZ";
  21.  
  22.             List<char> chars = new List<char>();
  23.             List<int> counts = new List<int>();
  24.  
  25.             for (int i = 0; i < inputString.Length; i++)
  26.                         {
  27.                 int count = 0;
  28.                 if (letters.Contains(inputString[i] ))
  29.                 {
  30.                     count = inputString.Split(inputString[i]).Length - 1;
  31.                 }
  32.                 else
  33.                 {
  34.                     continue;
  35.                 }
  36.                 if (count != 0)
  37.                 {
  38.                    chars.Add(inputString[i]) ;
  39.                    counts.Add(count);
  40.                    inputString = inputString.Replace(inputString[i], ' ');
  41.                 }
  42.                         }
  43.  
  44.             for (int i = 0; i < chars.Count; i++)
  45.             {
  46.                 Console.WriteLine("{0} --> {1}", chars[i], counts[i]);
  47.             }
  48.         }
  49.     }
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top