This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'dart:math'; | |
| void main() { | |
| print(pick(2, 10)); | |
| } | |
| int pick(int a, int b) => a + new Random().nextInt(b - a + 1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:path/path.dart' as path; | |
| void main() { | |
| var p = "/tmp/2239799170/foobar/"; | |
| print(p); | |
| if (p.endsWith(path.separator)) p = p.substring(0, p.length - 1); | |
| print(p); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'dart:convert'; | |
| void main() { | |
| var hello = "Hello world"; | |
| List<int> data = utf8.encode(hello); | |
| var s = base64.encode(data); | |
| print(s); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void main() { | |
| var s = "café-society"; | |
| var p = "café"; | |
| var t = s.startsWith(p) ? s.substring(p.length, s.length) : s; | |
| print(t); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void main() { | |
| var s = "café-society"; | |
| var p = "café"; | |
| var t = s.startsWith(p) ? s.replaceFirst(p,"") : s; | |
| print(t); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void main() { | |
| { | |
| var i = 0; | |
| var s = i.toString().padLeft(3,'0'); | |
| print(s); | |
| } | |
| { | |
| var i = 7; | |
| var s = i.toString().padLeft(3,'0'); | |
| print(s); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void main() { | |
| var x = 42; | |
| var s = []; | |
| s.add(x); | |
| var y = s.removeLast(); | |
| print(s); | |
| print(y); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void main() { | |
| var x = 8; | |
| var s = "Our sun has $x planets"; | |
| print(s); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void main() { | |
| var x = { | |
| "one": 1, | |
| "two": 2 | |
| }; | |
| var y = Map.of(x); | |
| x["three"] = 3; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void main() { | |
| var x = [ | |
| "a", | |
| "", | |
| "foo", | |
| "bar", | |
| "foo", | |
| ]; | |
| print("Before:\t x is ${x}"); | |