Created
October 9, 2020 22:20
-
-
Save guid-empty/5a4b14e71d288eab74bf4e239ae1ec11 to your computer and use it in GitHub Desktop.
Dart & Strings
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
/// | |
/// Flutter Mobile Developer | |
/// Strings | |
/// https://api.dart.dev/stable/2.10.1/dart-core/String-class.html | |
void main() { | |
// что насчет объявления строк? | |
final currentDateString = 'Current Date is ' + DateTime.now().toString(); | |
print(currentDateString); | |
// а можно с использованием интерполяции | |
final date = DateTime.now(); | |
print('можно так - текущая дата $date'); | |
print('но можно и так с использованием выражения - текущая дата ${DateTime.now()}'); | |
// а если строка состоит из отдельных частей? | |
final severalPartsString = 'Why ' + 'I ' + 'write ' + 'this ' + 'test ' 'in ' + 'this ' + 'style?'; | |
print(severalPartsString); | |
final severalPartsStringIsSimple = 'It ' 'is ' 'no ' 'need ' 'to ' 'use ' 'plus ' 'operator.'; | |
print(severalPartsStringIsSimple); | |
// что насчет multiline? | |
// если строка ну очень длинная и с переносами? | |
final soLongMultiLineTextSimple = '\nLorem Ipsum \n' | |
'Lorem Ipsum \n' | |
'Lorem Ipsum \n' | |
'Lorem Ipsum \n' | |
'Lorem Ipsum \n' | |
'Lorem Ipsum \n' | |
'Lorem Ipsum \n' | |
'Lorem Ipsum \n'; | |
print(soLongMultiLineTextSimple); | |
// а проще нельзя? а может сразу с интерполяцей? | |
final multiLineTextExpression = '''Кажется так проще - Lorem Ipsum | |
Lorem Ipsum | |
Lorem Ipsum | |
Lorem Ipsum | |
Lorem Ipsum | |
Lorem Ipsum | |
Lorem Ipsum | |
Lorem Ipsum | |
$severalPartsStringIsSimple | |
'''; | |
print(multiLineTextExpression); | |
// Ну ок.. | |
// А что будет, если умножить одно число на.... строку??? | |
// Ваши предположения? | |
// расскоментируйте следующую строку: | |
// print('Lorem Ipsum ' * 30); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment