I am an Arduino newbie and I am having trouble storing String in Arduino Library.... Any help on how to do this would be a life saver for me.
This is a glimpse of method I am trying to implement....!!!
#include<EEPROM.h>
String mystr[]="Hello World";
void setup() {
// put your setup code here, to run once:
That code creates an array of length 1, because the only initializer provided is the NULL that terminates the (empty) string. Then, it tries to write 20 characters to the 20 elements of the 1 element array.
One could piss away memory uselessly using a String object like so:
OP, You MUST store the length of the string that the useless String instance wraps in EEPROM, too, so that you have some clue what whoKnowsHowManyCharactersWereStored() should return.
One real solution for reading the saved String is that:
String IPis;
for(byte b=0 ; b < 15 ; b++){ //15 is the maximum lenght of an IP adress with dots
char f = EEPROM.read(b);
IPis += (f);
}
I run the for cycle 15 times, because I need to run 15 times. But you can change if you want to read a shorter or a longer String. The "char f" is needed because the String is stored in the EEPROM in ASCII format. And if you want to read like above PaulS it will results ASCII numbers in decimal values. Arduino Reference - Arduino Reference