Kann mir jemand einen Tipp geben, wie ich das Vorkommen aller Buchstaben in einem String zählen und ausgeben kann?
Danke!!
Gruß
schmitti81
Danke!!
Gruß
schmitti81
Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
Original von Elderan
Hallo,
wie wäre es mit Zählen?
Original von schmitti81
EDIT: Wie kann ich wissen an welche Stelle in dem Array 1 dazuaddiert werden muss, z.B. in einer switch-case Anweisung?! Ist aber nicht so schnell, oder?
Geht das auch anders?
Hashtable ht = new Hashtable();
string test = "das ist ein test das";
foreach (char buchs in test)
{
if (!ht.Contains(buchs))
{
ht[buchs] = 1;
}
else
{
ht[buchs] = ((int)ht[buchs]) + 1;
}
}
String[] astrWords2 = new String[ht.Keys.Count];
ht.Keys.CopyTo(astrWords2, 0);
Array.Sort(astrWords2);
foreach (String buchs in astrWords2)
{
Console.WriteLine("{0,-20} = {1,3}", buchs, ht[buchs]);
}
Console.Read();
string strbuchs = Convert.ToString(buchs);