#ifdef ... #endif inside a char array

Hi everyone.

What can I do to insert #ifdef#endif directives inside a char array definition?

For example:

const char webPage_REBOOTING[] PROGMEM = R"=====(
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="10;url=/">
<title>SmartHome</title>
</head>
<body>
<h1>REBOOT in 10 sec.</h1>

#ifdef DB
<h1>Prova DB</h1>
#endif

</body>
</html>
)=====";

Thank you

If you have them inside a string they will be treated as part of the string. Adjacent strings are merged so this will work:

#define DB "DatabaseFilePath"  // MUST BE IN QUOTES


const char webPage_REBOOTING[]  = R"=====(
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="10;url=/">
<title>SmartHome</title>
</head>
<body>
<h1>REBOOT in 10 sec.</h1>
)====="


#ifdef DB
"<h1>Prova " DB "</h1>"
#endif


R"=====(
</body>
</html>
)=====";

If the definition of DB doesn’t include quotes, use #DB between the strings. The ‘#’ tells the preprocessor to put quotes around the value.

Thanks, it works fine.
:slight_smile: