Hi. I need a solution in C++ or Java. Are there standard functions?
views:
487answers:
5There are no standard functions to do this in C++ - you need to roll your own. This apparent lack is because the concept of uppercase and lowercase, and indeed of words, is a lot more complicated than it might first seem. Your best bet is to use a regular expression library, such as the one that comes with Boost.
For Java, see Pattern. You can use \b
and \B
to match word boundaries. Case sensitivity can be enabled/disabled using the CASE_INSENSITIVE flag.
There's no single function that will do exactly that. It's still fairly trivial for simple cases: get the file in memory (e.g. std::vector<char> buff(file_begin_iter, file_end_iter);
) and then find what you want. (std::search
)
In C++ you can use regular expressions in
std::tr1::regex
if your compiler is up to date. Regular expressions support match case by default. Using \b Word boundaries you should be able to find whole words only.
In java: http://java.sun.com/docs/books/tutorial/essential/regex/bounds.html
You can use the "\b" word boundary.
P.S.: when you compile it remeber scape the slash: In ex.: To found the word 'dog' --> Pattern p = Pattern.compile("\bdog\b");