Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-lines string in Dart

Tags:

dart

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?

like image 369
Peter Avatar asked Oct 27 '12 22:10

Peter


People also ask

Can a string be multiple lines?

Raw StringsThey can span multiple lines without concatenation and they don't use escaped sequences. You can use backslashes or double quotes directly.

How do you print a new line in darts?

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.

What is string interpolation in Dart?

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.

How do you escape characters in Dart?

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.


1 Answers

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.

like image 138
Kai Sellgren Avatar answered Sep 21 '22 10:09

Kai Sellgren