PLEASE HELP! I have this String i recieve over wifi (esp8266)
[1023:1023:1023]
I want to split this up so i end up with 3 (int)Values
This is what i tried, but doesn’t work.
String val = webServer.arg(i); // [1023:1023:1023]
String trash = val.readStringUntil("[");
scanResultsRed[i]= (val.readStringUntil(":").toInt;
scanResultsGreen[i]= (val.readStringUntil(":").toInt;
scanResultsBlue[i]= (val.readStringUntil("]").toInt;
With this code i get this error:
‘class String’ has no member named ‘readStringUntil’
Can someone help me out?
Your parentheses seem off…
And if toInt is a method, you need parens there too. Why aren’t you tokenizing your string? Trim the brackets and split it on the :.
@Mark_Simmons I Don’t know what tokenizing is. Though the splitting is just what i try to do. Can you show me an example?
Strings do not read. Ports,Sockets,Streams and the like do, if you can send without brackets then you will not need to remove them.
Such that
webServer.arg(i); // 1023:1023:1023
But this should get you what you need.
val = val.replace("[","");
val = val.replace("]","");
String [] colorResults = val.split(":");
scanResultsRed[i] = (int) colorResults[0];
scanResultsGreen[i] = (int) colorResults[1];
scanResultsBlue[i] = (int) colorResults[2];
Thank you. I tried your code but i get errors.
class String’ has no member named ‘split’
and
val = val.replace("[","");
only works if i do this:
val.replace("[","");
and is this correct?
String [] colorResults = val.split(":");
or should it be:
String colorResults[] = val.split(":");
OK, so that makes me ask what language are you coding?
It is just an arduino sketch.
Ok, You may need to cast the webServer.arg(i) to a char pointer. Then run something like this.
char *val = “123:234:345:456”;
//char *val = (char *) webServer.arg(i);
int cnt = 0;
String str = “”;
String scanResults[3];
while(*val != ‘\0’){
if(*val == ‘[’ or *val == ‘]’)
{
val++;
continue;
}
if(*val == ‘:’)
{
scanResults[cnt] = str;
str = “”;
cnt++;
continue;
}
str += val;
}
Here you are looping through the pointer and testing for the “:” char. once found it sets the str into the array of results, and cleans up and increments for the next iteration of the loop and process till end of pointer. Let me know what you get… sorry earlier code was from Processing3.