Hello!
I would like to ask the following:
I'm writing a webserver html code to ESP8266 and there will be a lot of similar input fields/buttons/etc. My plan is to store these elements in a char [] and than with a small subroutine change the defining name-'s of the elements so I don't have to write down 20 times the same code with 1 different character but just the name of the char arrays.
I hope it make sense!
So example:
This is the html line of an input field:
"<ul><li><INPUT type='number' name='Tset_X' value='24' min='15' max='32'></li></ul>";
I would like to have this in a char array and than change the X with 1,2,3....
I've started to do it and of course I failed with the first line:
char button [] = "\"<ul><li><INPUT type='number' name='Tset_X' value='24' min='15' max='32'></li></ul>";"
I've read that to separate "" characters I'll have to use .
It seems to work but at the end of the sentence I couldn't find out the correct syntax.
I've tried:
</li></ul>";" missing terminating " character
</li></ul>"\;" stray in program
</li></ul>"\;\"
</li></ul>";""
</li></ul>";"""
So what else can I do?
EDIT:
Sorry, I've found out:
char InputField[] = "\"<ul><li><INPUT type='number' name='Tset_X' value='24' min='15' max='32'></li></ul>\";"
However the second question is still in the air:
And what do you think about the configurable button idea? Is it posible?
Thanks for any advise!
blh64
June 22, 2018, 2:01am
2
After you assign the string to InputField, you can use the standard string operators to search and/or replace the 'X' with whatever you want. If it is a 1 to 1 replacement (e.g. 'X' goes to '1' or '2' ..) then you can just write into the array at the specified index. If you want to replace it with a larger string, like "12" or "purple", then you will have to copy it.
J-M-L
June 22, 2018, 4:17am
3
For the second question InputField[41] = ‘1’;
would change your X into a ‘1’ (if I counted correctly up to its position, starting from 1st character being at index 0)
gyandras:
char InputField[] = "\"<ul><li><INPUT type='number' name='Tset_X' value='24' min='15' max='32'></li></ul>\";"
C++11 introduced raw string literals:
char InputField[] = R"FOO("<ul><li><INPUT type='number' name='Tset_X' value='24' min='15' max='32'></li></ul>";)FOO";
You can change the FOO parts (even leave them empty) to make sure they don't occur in the string.
J-M-L
June 22, 2018, 10:19am
5
oqibidipo:
C++11 introduced raw string literals:
char InputField[] = R"FOO("<ul><li><INPUT type='number' name='Tset_X' value='24' min='15' max='32'></li></ul>";)FOO";
You can change the FOO parts (even leave them empty) to make sure they don't occur in the string.
indeed!
char InputField[] = R"FOO("<ul><li><INPUT type='number' name='Tset_X' value='24' min='15' max='32'></li></ul>";)FOO";
void setup() {
Serial.begin(115200);
Serial.println(InputField);
Serial.println(F("------------------"));
for (char i = 0; i <= 5; i++ ) {
InputField[41] = '0' + i;
Serial.println(InputField);
}
}
void loop() {}
the serial monitor will show
[sub][color=purple]
"<ul><li><INPUT type='number' name='Tset_[color=red]X[/color]' value='24' min='15' max='32'></li></ul>";
------------------
"<ul><li><INPUT type='number' name='Tset_[color=green]0[/color]' value='24' min='15' max='32'></li></ul>";
"<ul><li><INPUT type='number' name='Tset_[color=green]1[/color]' value='24' min='15' max='32'></li></ul>";
"<ul><li><INPUT type='number' name='Tset_[color=green]2[/color]' value='24' min='15' max='32'></li></ul>";
"<ul><li><INPUT type='number' name='Tset_[color=green]3[/color]' value='24' min='15' max='32'></li></ul>";
"<ul><li><INPUT type='number' name='Tset_[color=green]4[/color]' value='24' min='15' max='32'></li></ul>";
"<ul><li><INPUT type='number' name='Tset_[color=green]5[/color]' value='24' min='15' max='32'></li></ul>";
[/color][/sub]
(careful, the start and end quotes will be in there)