Search text

This is a discussion on Search text within the C++ Programming forums, part of the General Programming Boards category; How do you search a string of text for 1+ word(s)? I would assume that Code: template <class ForwardIterator1, class ...

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    45

    Search text

    How do you search a string of text for 1+ word(s)? I would assume that
    Code:
    template <class ForwardIterator1, class ForwardIterator2>
       ForwardIterator1 search ( ForwardIterator1 first1, ForwardIterator1 last1,
                                 ForwardIterator2 first2, ForwardIterator2 last2 );
    only works for numerical values.

  2. #2
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    Does this help?

  3. #3
    Registered User
    Join Date
    Jun 2009
    Posts
    45
    Yes, thanks!

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    A string is a container of characters, so if you had a sequence of characters to search for then the search function you listed could work (I assume that's from the standard library). Note that this means that if you had more than one word then they would all have to be consecutive and part of a single search string.

    Perhaps a better option for searching in strings is the find family of functions implemented for the standard string class (as linked to by linuxdude). They will likely give you more flexibility.

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> I would assume that

    It's a generic algorithm - it works for any compliant type. If you want to use it for this, just pass it iterators to the beginning and end of the target and pattern, respectively. If it returns the end iterator of 'target', the search failed, otherwise just increment the begin iterator to 'target' and repeat the search until no more are found.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String search in two text files
    By ab-c in forum C Programming
    Replies: 2
    Last Post: 07-14-2008, 04:01 AM
  2. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 01:59 PM
  3. How to use FTP?
    By maxorator in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2005, 02:17 PM
  4. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 08:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21