Last active
July 3, 2019 07:33
-
-
Save nikli2009/ebd554ac1fd69918573ce0599fdb3b19 to your computer and use it in GitHub Desktop.
Dart Variables
This file contains 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() { | |
// Way 1 | |
print('----Declare Way 1----'); | |
var unlimited; | |
unlimited = 'unlimited'; | |
print(unlimited); | |
// 'unlimited' => 1000.00, ALLOWED | |
unlimited = 1000.0; | |
print(unlimited); | |
// Way 2 - Recommended | |
print('----Declare Way 2----'); | |
String name = 'nikk1'; | |
int age = 20; | |
double salary = 1000.00; | |
bool married = true; | |
print(name); | |
print(age); | |
print(salary); | |
print(married); | |
// 'nikk1' => 1000.00, NOT ALLOWED | |
// name = 1000.00; | |
// ---------- Properties ---------- // | |
String properties = '\t I bought a new iPhone \n'; | |
print('------properties-------'); | |
print(properties.length); // 25 | |
print(properties.trim().length); // 21 | |
properties = ''; | |
print(properties.isEmpty); // true | |
properties = ' \t\n'; | |
print(properties.isEmpty); // false | |
print(properties.trim().isEmpty); // true | |
properties = null; | |
// print(properties.isEmpty); => Error | |
String unintialized; | |
print(unintialized); // null | |
// print(unintialized.isEmpty); => Error | |
// print(unintialized.isNotEmpty); => Error | |
// substring | |
// @String | |
print('----1. substring----'); | |
print(name.substring(0)); // nikk1 | |
print(name.substring(1, 3)); // ik | |
// startsWith | |
// @String | |
print('----2. startWith----'); | |
print(name.startsWith('i')); // false | |
print(name.startsWith('i', 1)); // true | |
print(name.startsWith(new RegExp(r'\w'))); // true | |
print(name.startsWith(new RegExp(r'\d'))); // false | |
print(name.startsWith(new RegExp(r'\d'), 4)); // true | |
print(name.startsWith(new RegExp(r'[A-Za-z]'))); // true | |
print(name.startsWith(new RegExp(r'[A-Za-z]{1}'), 4)); // false | |
print(name.startsWith(new RegExp(r'[A-Za-z]{5}'))); // false | |
// split | |
// @List | |
String sentences = 'John took 20 min to resolve this; John just left office'; | |
print('----3. split----'); | |
print(sentences.split(';')); // ['John took 20 min to resolve this', 'John just left office'] | |
// replaceAll | |
// @String | |
print('----4. replaceAll----'); | |
String unpurified = 'Johnny really loves drugs and guns'; | |
print(unpurified.replaceAll(new RegExp(r'(drugs|guns)'), '***')); // Johnny really loves *** and *** | |
// toLowerCase | |
// @String | |
print('----5. toLowerCase----'); | |
String playername = 'Kevin Snake'; | |
print(playername.toLowerCase());// kevin snake | |
print(playername.toUpperCase()); // KEVIN SNAKE | |
// Value Checking | |
// playername = null | |
print('----6. Value Checking----'); | |
playername = null; | |
print(playername); | |
if (playername == null) { print('yes');} // yes, playername == null | |
// print(playername.toLowerCase()); => Exception | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment