Is there an easy way to parse a std::string in search of a list of certain charcters? For example, let’s say the user enters this<\is a.>te!st string. I’d like to be able to spot those non-letter characters are there and do something about it. I’m looking for a general purpose solution that allows me to simply specify a list of chars so I can reuse the function in different situations. I’m guessing regular expressions will play a key role in any solution, and obviously the more compact and effience, the better.
Is there an easy way to parse a std::string in search of a list
Share
You could use
std::string::find_first_not_of()for this. It’ll find the characters except those in the set that you give it. Its counterpart,find_first_of(), will search for characters that are in the set.Both functions allow you to specify the starting index. This will enable you you to continue the search from where you left off.