-5

Is there a way to take an input string, store it into a array and then pass each index of that array to a variable to hold before being overwritten by the next array index value?

For example:

A number of input values which are of type:String are being created

String 1 is given as "Value: 7.93 22-10-2017 10:33:32"
String 2  is given as "Value: 8.93 22-10-2017 12:10:15"
.
.
.
String 10  is given as "Value: 6.93 22-10-2017 18:03:04"

The string structure is known but its contents as such will vary

After a time period of say 60sec. The contents of array[0] which will be String 1 will be assigned to a given variable "output"

After the next 60sec time period .The contents of array[1] Which will be String 2 will be stored into the same "Output" variable in which the previous value will be now overwritten

This continues until array[9] i.e String 10 in which the array will begin over and start to populate "output" with newly presented string values

3
  • 4
    idownvotedbecau.se/imageofcode
    – gre_gor
    Dec 8, 2017 at 19:11
  • 1
    Also, please tell us what you are trying to achieve. Passing an index to a variable is not the real goal, but only the means to an end. What is your real goal? Dec 8, 2017 at 20:48
  • Originally I was attempting to pass the characters of each string using the toCharArray() function. The solution was much simpler and straight forward in the end. I've posted it below.
    – Tino88
    Dec 11, 2017 at 20:46

1 Answer 1

0

Solution Used Below:

// Input 1-3 represents input string

String Input1 ="Value: 7.93 22-10-2017 10:33:32";
String Input2 ="Value: 8.93 22-10-2017 12:10:15";
String Input3 ="Value: 8.93 22-10-2017 12:10:15";
String message[] ={Input1,Input2,Input3};

// Assigned 'Output' Variable will be populated by each index of the array
String Output;

  void setup()
   {
        Serial.begin(9600);
   }


// Each index of the array will be stepped through and passed to 'Output'
//delay() will control period between each index value

void loop()
     {
         for (int i = 0; i < 3; i++)
            {
                  Output=message[i];
                  Serial.println(Output);
                  delay(5000);
            }

     }

Not the answer you're looking for? Browse other questions tagged or ask your own question.