Dart overview
Sample method
String myName () {
return 'Stephen';
}Main method
void main ( ) { … }
Variable declaration
var name = myName(); const value = 1000;
Type System
Built-in Types
Number types
var y = 1; var hex= 0xDEADBEEF; var y = 1.1; var exponents = 1.42e5;
double z = 1; // equalst to z=1.0
Numbers to String and back
int. parse(‘1’);
double. parse(‘1.1’);
1. toString();
3. 14.toStringAsFixed(2);
Bitwise Operators
«_space;» & |
What is a String?
UTF-16 unit sequence
Create Strings
var s1 = 'Single quotes work well for string literals.'; var s2 = "Double quotes work just as well."; var s3 = 'It\'s easy to escape the string delimiter.'; var s4 = "It's even easier to use the other delimiter.";
String expressions
var s = 'string interpolation'; 'Dart has $s, which is very handy.'
String equality
The == operator tests whether two objects are equivalent. Two strings are equivalent if they contain the same sequence of code units.
Concat Strings
You can concatenate strings using adjacent string literals or the + operator:
var s1 = 'String '
'concatenation'
" works even over line breaks.";Multi-line string
use a triple quote with either single or double quotation marks:
var s1 = ‘’’
You can create
multi-line strings like this one.
‘’’;
Raw String
You can create a “raw” string by prefixing it with r: var s = r'In a raw string, not even \n gets special treatment.';