import 'package:characters/characters.dart'; //use characters library
void main() {
//There is no Character type
var char = 'a'; // String
//String type immutable
var txt0 = "I'm text.\n"; // String literal can use ""
var txt1 = 'I\'m text'; // or '' (Dart way)
print(txt1);
print(txt1.length);
print(txt1.codeUnits); // collections of UTF-16 code units
print(txt1.runes); // Unicode code points - runes
print(txt1.characters.length); // Unicode grapheme clusters, use characters library
//Unicode
print('I \u2764 Dart\u0021'); // hex code for the heart emoji and '!'
print('I love \u{1F3AF}'); // use {} after FFFF value
//Concatenation
txt1 += '!';
print('[' + txt1 + ']');
//Interpolation
print('Hi, $txt1');
//StringBuffer
final txt2 = StringBuffer();
txt2.write('Hello, ');
txt2.write('Dart!');
print(txt2.toString());
//Multi-line (''' or """)
const txt3 = '''
- line 1
- line 2
- line 3''';
print(txt3);
//raw string (r' ' or r" ")
print(r'C:\temp');
//Methods
var str = 'Dart is cool!'.toLowerCase();
str = str.toUpperCase();
print(str);
print(str.contains('IS'));
print(str.replaceAll('IS', 'IS REALLY'));
}
суббота, 3 апреля 2021 г.
Strings
Подписаться на:
Комментарии к сообщению (Atom)
Комментариев нет:
Отправить комментарий