10-31-2011، 02:32 PM
شمارش تعداد تکرار یک کلمه در رشته
کد:
Get Frequence of word in string
int GetFreq(string word)
{
string st = null;
st = 'StringThatContainWord';
int start = 0, count = 0, curr = 0;
int last = st.LastIndexOf(word);
do
{
curr = st.IndexOf(word, start);
if (curr != -1)
{
count++;
start = curr + 1;
}
}
while (last != curr);
return count;
}