Search for more symbols with string command

This is a discussion on Search for more symbols with string command within the C++ Programming forums, part of the General Programming Boards category; Hello. I have a simple question. If I wanna search for . I use this way. Code: word.find('.')!= string::npos is ...

  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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,509
    Err... find can also take a (sub)string or a const char*, so you can just put that "foo" right inside find.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,509
    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 07:43 AM.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  5. #5
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,625
    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, 07:51 PM
  4. String Search
    By slowprogrammer in forum C Programming
    Replies: 5
    Last Post: 05-25-2010, 01: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

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