example: "select * from somewhere where x = 1
"
I want to find the whitespace-delimited "where
", but not the "where
" within "somewhere
". In the example "where" is delimited by spaces, but it could be carriage returns, tabs etc.
Note: I know regex would make it easy to do (the regex equivalent would be "\bwhere\b
"), but I don't want to add a regex library to my project just to do this.
If you are using Visual Studio 2008 with Feature Pack you already have std::tr1::regex in C++.
Pretty fast and doesn't need to construct heavy
istringstream
objects.If you wanted to use the pure MFC method of string manipulation, then this should work:
Well, regex is the correct answer. If you don't want to include regex, you will have to try and implement a bit of regex yourself and search for " where ".
Your only other option I guess would be to search for "where", then check the character before and after the match to see if they are whitespace characters.
I don't know the first thing about MFC and
CString
, but in plain C++ I'd stuff that string into anstd::istringstream
and read from that into a string:I suppose
CString
does have stream operators overloaded with the appropriate semantics, but, as I said, I don't know it.