Hey all I am trying to convert a string into a uint8_t with the following code:
String data = "#255101987";
String tmp1 = data.substring(1, 3);
uint8_t first = (String)tmp1;
I am getting the error of:
cannot convert 'String' to 'uint8_t {aka unsigned char}' in initialization
Any help would be great as I thought adding (String) in front of the varible would solve the issue but it hasn't as you can tell.
asked Jun 29, 2015 at 5:31
-
Do you want the ASCII value of the character or do you want to parse the string contents as a number?Ignacio Vazquez-Abrams– Ignacio Vazquez-Abrams2015年06月29日 06:38:49 +00:00Commented Jun 29, 2015 at 6:38
-
I presume from the substring call s/he expects to find 255 in the variable.Nick Gammon– Nick Gammon ♦2015年06月29日 08:46:39 +00:00Commented Jun 29, 2015 at 8:46
-
@NickGammon is correct. I am looking for the 255 within the string and needing to convert that to the uint8_t.StealthRT– StealthRT2015年06月29日 17:01:11 +00:00Commented Jun 29, 2015 at 17:01
1 Answer 1
uint8_t first = atoi (tmp1.substring(1, 3).c_str ());
Or even:
String data = "#255101987";
uint8_t first = atoi (data.substring(1, 3).c_str ());
answered Jun 29, 2015 at 6:12
-
That worked great. Thanks for the help, Nick!StealthRT– StealthRT2015年06月29日 22:52:06 +00:00Commented Jun 29, 2015 at 22:52
Explore related questions
See similar questions with these tags.