#include <Streaming.h>
void setup()
{
Serial.begin(115200);
String s = "0,2,1,12";
int valueArray[8] = { 5,5,5,5,5,5,5,5 };
splitValue(s, valueArray, 3);
for (int i=0; i<8; i++)
Serial << valueArray[i] << "\n";
}
void splitValue(String valueString, int *valueArray, int ArraySize)
{
int i=0;
int pos;
do {
if (i>=ArraySize) break;
pos = valueString.indexOf(',');
if (pos != -1)
{
//Serial << valueString.substring(0, pos) << ",";
valueArray[i++] = valueString.substring(0, pos).toInt();
valueString = valueString.substring(pos+1, valueString.length());
} else {
if (valueString.length()>0) {
//Serial << valueString << ",";
valueArray[i++] = valueString.toInt();
}
}
} while (pos >=0);
//Serial << "\n";
while(i< ArraySize)
valueArray[i++] = 0;
}
void loop()
{
}
沒有留言:
張貼留言