uint16_t count;
uint16_t *code_array;
String tmp_str;
// Remove the leading "1:1,1," if present.
if (str.startsWith("1:1,1,"))
tmp_str = str.substring(6);
else
tmp_str = str;
// Find out how many items there are in the string.
count = countValuesInStr(tmp_str, ',');
// Now we know how many there are, allocate the memory to store them all.
code_array = newCodeArray(count);
// Now convert the strings to integers and place them in code_array.
count = 0;
uint16_t start_from = 0;
int16_t index = -1;
do {
index = tmp_str.indexOf(',', start_from);
code_array[count] = tmp_str.substring(start_from, index).toInt();
start_from = index + 1;
count++;
} while (index != -1);
截取的代码 |