Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Count occurences of Character
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { String str = "aaa b bdd h aaa k "; int ch = countOccurencesOfChar(str, 'a'); } public static int countOccurencesOfChar(String str, char c) { Dictionary<char,int> dict = new Dictionary<char,int>(); dict.Add(str[0],1); for(int i=1; i< str.Length; i++) { if(dict.ContainsKey(str[i])) dict[str[i]]++; else dict.Add(str[i],1); } foreach (KeyValuePair<char,int> keypair in dict) { if(keypair.Key==c) { Console.Write(keypair.Value); return keypair.Value; break; } } return 0; } } }
run
|
edit
|
history
|
help
0
sdfghjtrefdc v
Lottery
equation with a variable on the 2nd power
ElaineBrown**
Date Example
Convert integer into bit string
Merging and sorting 2 arrays using LINQ
1 -5 6 x1=3 x2=2
Basma 2
project euler 13, C#