I'm looking to determine if an Arduino String contains any other character than those that would be in the [number],[number]'\r''\n'
where [number]
could be positive or negative.
I know I can run a for down the entire string and use if(isDigit([char]) || isWhitespace([char])||[char]=='-')
however, I imagine there's a better way to do this.
Could I (for example) convert the String to an array of values and search the array for any value that doesn't correspond to the characters I'm looking for? Or is there a better way to check this out?
1 Answer 1
There is a better way, which is called regular expressions (or regexp). However, afaik these are not supported by Arduino by default.
However, I'm sure you can find some 'generic C++' class that can handle them.
For that, it's best to check on StackOverflow.com probably.
After a short check, on the Arduino forum there is a library available for regexp:
It is created by Nick Gammon, so all credits are for him.
.indexOf()
, which saves you the inner loop and is probably faster than hand-coding it.