FINDing within strings

this - find -

The avr-gcc compilers and, in particular, the Arduino distribution do not directly support any of the C++ STL (Standard Template Library) classes. No std::string stuff no std::vector stuff. The limited resources of chips like the ATMega328p restricts the things that we can do. Bummer.

If you are using a version earlier than arduino-0019, I suggest that you stick with C-style "strings" and their standard C library functions. I looked briefly at the downloadable String class when I first started with Arduino a couple of months ago and I really, really (really) didn't like what I saw. The first two things that I tried didn't work, and there are numerous references to memory leaks in threads in this forum. Bottom line: Lots of bugs, and it's just downright butt-ugly (in my opinion). Maybe some of the ugliness that I perceived was due to someone's attempt to "fix" some of the worst of the bugs---I just don't know.

However...

For arduino-0019 there is a "String" class (note the upper-case 'S') that has some of the convenience (but not all of the functionality) of the standard C++ library std::string class. Browse the source code and look at examples supplied with arduino-0019 to see whether you like it. It certainly seems cleaner to me than the older "unofficial" String class, but I haven't fully evaluated it to see if I might want to use it. Maybe you can find something there that meets your needs.

If you can't find something that's already there, then maybe you can add a new member function to the class (it's open source after all) to get the standard C library function strstr(const char *haystack, const char *needle) to do the work of finding whether a substring is part of a given string. Or, you can just pretend it's C and not C++ and use C-style "strings" and their standard library functions (which are supported by avr-gcc).

Regards,

Dave