Showing posts with label String to integer. Show all posts
Showing posts with label String to integer. Show all posts

Friday, 4 May 2012

Convert a String to an Integer

I think that a lot of people is looking for a function to convert a string to an integer because the function ATOI works only with char. 

This is the solution for you project with Arduino:
int stringToNumber(String thisString) {
int i, value, length;
length = thisString.length();
char blah[(length+1)];
for(i=0; i<length; i++) {
blah[i] = thisString.charAt(i);
}
blah[i]=0;
value = atoi(blah);
return value;
}