ForumKalbi.Com

ForumKalbi.Com (https://www.forumkalbi.com/index.php)
-   Bilgisayar (https://www.forumkalbi.com/forumdisplay.php?f=220)
-   -   C# String Operations (https://www.forumkalbi.com/showthread.php?t=4647)

Candres 27 Ocak 2024 18:56

C# String Operations
 
C# String Operations
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]);
}
}
}
}


Forum saati; Türkiye'ye göre ayarlanmış olup, şu an saat: 12:48.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Navbar with Avatar by Motorradforum