I'm still working on Dart. I just want to output my string defined in .dart to my html. I look into the documentation on https://sites.google.com/site/dartlangexamples/learn/variables/strings
I understand that I need to use the """.
When I print my query, I got the good result, but when I output it in html, They are side to side.
There it is:
.dart :
var symbole = """ * *** ***** ******* *********"""; var element03 = query('#exercice03'); element03.innerHTML = symbole; print(symbole); }
The Print give me exactly what I set into my var symbole BUT, in my HTML i got this:
My html is : <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>HelloWorld</title> <link rel="stylesheet" href="HelloWorld.css"> </head> <body> <div id="container"> <p class="question">Exercice : Pritn the * : <span id="exercice03"></span></p> </div> <script type="application/dart" src="web/HelloWorld.dart"></script> <script src="https://dart.googlecode.com/svn/branches/bleeding_edge/dart/client/dart.js"></script> </body> </html>
I don't understand why in my output html I dont get the same result as my Print in my dart editor, can some one help me to figure this out?
Raw StringsThey can span multiple lines without concatenation and they don't use escaped sequences. You can use backslashes or double quotes directly.
Fortunately Dart has a built-in feature that allows us to split a String by newline. LineSplitter , which is part of Dart's convert API, can be used to split a String by CR , LF , or CR + LF . So, we don't need to create a new function. It returns List <String> , which means we can iterate the result.
String interpolation is the process of inserting variable values into placeholders in a string literal. To concatenate strings in Dart, we can utilize string interpolation. We use the ${} symbol to implement string interpolation in your code.
By default, Dart will escape < & > , " (double quote), ' (apostrophe), and / (slash). However, you can choose what you want to escape by passing an optional parameter to the HtmlEscape whose type is HtmlEscapeMode . Below are list of modes provided by Dart along with what characters are escaped by each mode.
I'm not sure if I follow you here -- do you want this?
var symbole = """ *<br /> ***<br /> *****<br /> *******<br /> *********<br />"""; var element03 = query('#exercice03'); element03.innerHTML = symbole;
I just added the break lines
So as Matt B said, the output of print()
is differently formatted than HTML on the browser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With