Anyone know how I would go about converting a String object "123" into integer x=123?
I could write some low level method to do it, but I was hoping this is already done.
Anyone know how I would go about converting a String object "123" into integer x=123?
I could write some low level method to do it, but I was hoping this is already done.
int x=atoi("123");
cool. But now:-
int vx = atoi(line.substring(line.indexOf("x="), line.indexOf("&y=")));
gives
error: cannot convert 'String' to 'const char*' for argument '1' to 'int atoi(const char*)'
atoi has only one parameter it accepts, you are giving it two!!
atoi has only one parameter it accepts, you are giving it two!!
No, he's not. He's trying to pass it a String, rather than a char *.
You'll need to store the substring in another String, then extract the char array from the String to pass to atoi.
I had an atoi issue when moving from 0018 to 0021 below.
The String Library in 0021 is broken. The const char *() operator is commented out in WString.h.
My best advice is not to use WString use C-style strings.
Korman
sounds complicated.
Can anyone give me an example of this?
You can use the toCharArray method to extract the char array from the string, to pass to the atoi function:
int n;
char carray[6];
readString.toCharArray(carray, sizeof(carray));
n = atoi(carray);
Thanks All.
I'll try that when I get home. Hopefully that is the last step in getting a wireless bot controlled with a web interface up and running.