Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace CountCharsInAString
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Enter your string here: ");
- string line = Console.ReadLine();
- Dictionary<char, int> charList = new Dictionary<char, int>();
- foreach(char c in line)
- {
- if((int)c == 32)
- {
- continue;
- }
- else if (charList.ContainsKey(c))
- {
- charList[c]++;
- }
- else
- {
- charList.Add(c, 1);
- }
- }
- foreach(var ch in charList)
- {
- Console.WriteLine(ch.Key + " -> " + ch.Value);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment