Kod:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
class StringOperations
{
// cümledeki istenen harfi sayar
public int harfSay(string cumle, char harf)
{
int sayac = 0;
for (int i = 0; i < cumle.Length; i++)
{
if ((cumle[i].ToString().ToUpper()[0] == harf)
|| cumle[i].ToString().ToLower()[0]==harf)
sayac++;
}
return sayac;
}
//kelime sayımı..
public int harfSay(string cumle, string harf)
{
int sayac = 0;
for (int i = 0; i < cumle.Length; i++)
{
if (cumle[i].ToString() == harf)
sayac++;
}
return sayac;
}
public string[] kelimelereParcala(string cumle)
{
string[] kelimeler = new string[kelimeSay(cumle)];
cumle = cumle.Trim();
int index = 0;
int sayac = 0;
while (cumle.IndexOf(' ') != -1)
{
index = cumle.IndexOf(' ');
kelimeler[sayac++] = cumle.Substring(0, index);
while (cumle[index + 1] == ' ')
index++;
cumle = cumle.Substring(index + 1);
}
kelimeler[sayac] = cumle;
return kelimeler;
}
public int kelimeSay(string cumle)
{
int sayac = 0;
cumle=cumle.Trim();
for (int i = 0; i < cumle.Length; i++)
{
if (cumle[i] == ' ')
{
sayac++;
while (cumle[i+1] == ' ')
i++;
}
}
return sayac+1;
}
public int kelimeSaySubstring(string cumle)
{
int sayac = 0;
cumle = cumle.Trim();
int index;
if (cumle == "")
return 0;
while (cumle.IndexOf(" ")!=-1){
index = cumle.IndexOf(" ");
sayac++;
while (cumle[index + 1] == ' ')
index++;
cumle = cumle.Substring(index + 1);
}
return sayac+1;
}
public void display(string[] kelimeler)
{
for (int i = 0; i < kelimeler.Length; i++)
{
Console.WriteLine(kelimeler[i]);
}
}
}
}