Witam, uczę się języka C#.
Mam problem w zanalizowaniu tekstu (np. po wpisaniu słowa "kot" komputer ma wyświetlić 1-k, 1-o, 1-t).
Napisałem poniższy kod, czy da się go jakoś skrócić nie dodając całej reszty alfabetu (tak jak ja to zrobiłem z literą "a")?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ile_poszczegolnych_literek_ma_dane_zdanie
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Napisz zdanie, a komputer je zanalizuje.");
string tekst = Console.ReadLine();
int a = 0;
int start = 0, pozycja = 0;
while ((pozycja = tekst.IndexOf("a", start)) >= 0)
{
start = pozycja + 1;
a += 1;
}
Console.WriteLine("Liczba literek \"a\" wynosi " + a);
Console.ReadKey();
}
}
}