Eralt / arduino

Automatically exported from code.google.com/p/arduino
0 stars 0 forks source link

Ascii functions to help with string library #399

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
A couple of functions that would help with string parsing. Can we get these in 
the core?

#define isDigit(n) (n >= '0' && n <= '9')

#define charToInt(c) (atoi(c))

Original issue reported on code.google.com by tom.i...@gmail.com on 13 Nov 2010 at 6:21

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Here's another useful function, stringToInt().  Should probably be re-written 
using only a char array, but it works great with Strings as is:

int stringToInt(String thisString) {
  int value = 0;
  for (int charPos = 0; charPos < thisString.length(); charPos++) {
    int thisChar = thisString.charAt(charPos);
    if (isdigit(thisChar)) {
      value = value * 10;
      value = value + (thisChar - '0');
    }
  }
  return value;
}

Original comment by tom.i...@gmail.com on 23 Nov 2010 at 11:27

GoogleCodeExporter commented 9 years ago
Maybe also:

#define isLetter(char c) (c >= 'A' && c <= 'Z')

Original comment by tom.i...@gmail.com on 23 Nov 2010 at 11:31