CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2005
    Posts
    1,828

    Thumbs up Find the number of entries of a particular string

    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?

  2. #2
    Join Date
    Dec 2002
    Location
    St.Louis MO, USA
    Posts
    672

    Re: Find the number of entries of a particular string

    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.
    A Person who is polite is given goodness and a person who is away from Politeness is away from Goodness.

    NAUMAAN

  3. #3
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Lightbulb Re: Find the number of entries of a particular string

    Quote Originally Posted by maverick786us
    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.

    Code:
     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;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured