• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Strings, including " characters in them.

Status
Not open for further replies.

dr pepper

Well-Known Member
Most Helpful Member
In building a esp8266 web page I'm sending html and css tags as part of a string:-

content += "<div id="progress">";

As you can see I use lines content += to add some text to a string, I like to do it this way, however the word progress has quote marks around it, the arduino then breaks the sentence into 2 strings either side of 'progress' and 'thinks' the word progress is a variable and messes up.

Is there a way I can build up a string and have " marks within it, html requires them.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
The arduino is based on C++ so you ned to escape the "... BUT!! this will mess the HTML code... Try the HTML quote system..
content+= "<div id=&quot;progress&quot;>";

I dont know if this will work but I know if you escape " in C/C++ The HTML code may not be able to parse it!!
 

dr pepper

Well-Known Member
Most Helpful Member
Sussed.
You were not quite correct Mr. Rogers, it might have been that courvoisier, but you put me on the right lines.

&quot works for the text portion of a page, &quot; get lost &quot; prints:
"get lost"
But it doesnt seem to work inside html tags.
Looking at a ascii table I also found &#34 which is html for " and it works but with the same restrictions as just mentioned.
However the arduino ide has a way of dealing with this, and its simple just \" , so Serial.println("\"GET LOST\""); would print -
"GET LOST"
My modified html progress bar now does indeed work.
Thanks.
 

dougy83

Well-Known Member
If you get tired of escaping the double-quote marks, just use single-quotes; they're just as acceptable in HTML.

e.g. content += "<div id='progress'>";
 

dr pepper

Well-Known Member
Most Helpful Member
Thanks Doug, that would make for a more readable line of code, 'silly' is a lot neater than \"silly\".
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top