Thread: Search for more symbols with string command

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    29

    Search for more symbols with string command

    Hello.

    I have a simple question.

    If I wanna search for . I use this way.

    Code:
    word.find('.')!= string::npos
    is it possible to search for like ',.!' etc? To search for more symbols instead of using that code again, and again like:

    Code:
    word.find('.')!= string::npos || word.find(',')!= string::npos
    Your Sincerly Lovelace

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Err... find can also take a (sub)string or a const char*, so you can just put that "foo" right inside find.

  3. #3
    Registered User
    Join Date
    Sep 2011
    Posts
    29
    Quote Originally Posted by manasij7479 View Post
    Err... find can also take a (sub)string or a const char*, so you can just put that "foo" right inside find.
    Im not sure I understand what you mean?

    Im trying to search for more then just ".", im scanning a line and I wanna scan for ,.!¤%&/ etc too, can I do that with one find?

  4. #4
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Yes (if you mean, search for ",.!¤%&/" ), read the reference.
    string::find - C++ Reference

    If you want to search for the characters individuallly, you're better of with if--else
    Last edited by manasij7479; 03-17-2012 at 06:43 AM.

  5. #5
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Search command output for string
    By theitsmith in forum C Programming
    Replies: 6
    Last Post: 01-21-2012, 05:39 PM
  2. Help with search <string.h>
    By athene in forum C Programming
    Replies: 6
    Last Post: 12-09-2011, 08:41 PM
  3. Find index of last char in search string in string?
    By Programmer_P in forum C++ Programming
    Replies: 6
    Last Post: 06-07-2010, 06:51 PM
  4. String Search
    By slowprogrammer in forum C Programming
    Replies: 5
    Last Post: 05-25-2010, 12:39 AM
  5. String Search with command line arguments
    By goron350 in forum C Programming
    Replies: 5
    Last Post: 11-29-2004, 05:56 PM