Click to See Complete Forum and Search --> : Find the number of entries of a particular string


maverick786us
October 10th, 2005, 11:15 PM
Can anyone show me an example in which the user has to find the number of times a string is displayed in a bigger string irrespective of spaces?

Naumaan
October 10th, 2005, 11:54 PM
You have to find ur substring with basic_string::find function from begining to end, if u found ur substring then find again from next position(returned by find function) and so on untill end.
Hope this helps u.

humptydumpty
October 11th, 2005, 12:10 AM
Can anyone show me an example in which the user has to find the number of times a string is displayed in a bigger string irrespective of spaces?

you can do like this this is a Simple Program and on your Button Click it will find the given substring in a string .First start from 0 if string Found Count the Position increment it and then find the string in next string
e.g in Two edit Box Enter One Main string in First and in Second enter string to be found and on your Button Click write the function to search the substring in the string.and in your main sub string if string found set the focus on the string.here iNext3 is the member variable of your class.


CString str1;
CString str1;
BSTR bstrMess=NULL;
m_Edit11.GetWindowText(&bstrMess);;
str1 = ::SysAllocString(bstrMess);
int iText =str1.GetLength();
CString ptr1 = str1.Right(iText-iNext3);
int n= ptr1.Find(strText,0);
int j=strlen(strText);
m_Edit11.SetSel(iNext2+n,iNext3+n+j);
iNext3 += n+j;