[SOLVED] Assigning terminal inputs to indexes in a array

I have been working on this a while and I cannot seem to figure it out. Essentially, I am using the Terminal Widget to sent String inputs to my Arduino board. My code is below:

String INFO; String fromTerminal = param.asStr(); int indexstart = fromTerminal.indexOf(","); int indexend = fromTerminal.lastIndexOf(","); int counter = indexstart - indexend; INFO[counter] = fromTerminal;

My thoughts on the code was, based on the number of “,” I enter in the string then that will assign my input to an index within the INFO array. However as I have tried several different things, I constantly get errors such as:
cannot convert ‘String’ to ‘char’ in assignment.
Oddly enough if I set: INFO[counter] = fromTerminal.toInt();
I dont get an error but I dont think that will allow me to print out my actual input. Any help is much appreciated, thanks!

There are Arduino functions called toStr, toInt etc. You may wanna check these out on the Arduino site :slight_smile:

Since I declared the terminal input as a string (param.asStr()) I dont think I need to convert it using toStr. And I dont want to use toInt() because then any non integer information would be lost.

The issue seems to be something that in order to put the string into an index within an array it is trying to convert it to character but it cant. Not sure.

EDIT: It looks like because I wasnt allocating an array size upfront that was causing the error,

@philmurp you can do much simpler

String s = param.asStr(); int commaCount = s.length();

Wouldnt that count the entire length of the input?

An example input I would have would be:


So from that I would want to put the integer 60 in the index[2] of the array.

Ah, ok. I thought you just send commas.