[Flutter] String of Dart data type
1. Write in front
Introduced in the previous articleDart
Numeric types in the primitive data types of ,on one
types (int and double), then continue learning nowDart
The basic syntax of the string typestring
.
[Flutter] Apple Mac computer configuration flutter development environment
[Flutter] Android Studio installs a third-party emulator - Netease MuMu
[Flutter] Project running error Failed to find Build Tools revision 29.0.2
【Flutter】flutter doctor 报错Android license status unknown. Run `flutter doctor --android-licenses‘
[Flutter] How to create a new project and run your first flutter project
[Flutter] Basic use of var, final and const in Dart
[Flutter] num of Dart data type
2. String
2.1 Basic Definitions
String usageapostrophe
andDouble quotes
Yes, the test code is as follows:
void stingTest(){
var a = 'jay';
var b = "reno";
print(a+b);
}
- 1
- 2
- 3
- 4
- 5
The results are as follows:
2.2 String concatenation
Strings can be added directly for splicing, and strings can also be used directlyString
,as follows:
void stingTest(){
var a = 'jay';
var b = "reno";
print(a+b);
String name = 'reno';
print(name);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
The result of running the code is as follows:
2.3 Multi-line strings
triple quotes
andDouble quotes
Multi-line strings can be displayed, and the test is as follows:
void stingTest ( ) {
String name = 'reno' ;
print ( name ) ;
//Triple and double quotes can display multi-line strings
String name1 =
"zjp\n"
"jay\n"
"reno\n" ;
print ( name1 ) ;
String name2 = '''zjp
jay
reno1
''';
print(name2);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
The print result is as follows:
three quotation marks
willspace
Also print it out, restore the format of the original string, and output it according to the format.
2.4 Take the specified subscript character
Strings can also take specified characters, which is as convenient as arrays.
2.5 String Multiplication
Interestingly, strings can also be added and multiplied, but not subtracted and divided.
2.6 String format output
The format output of the string is as follows:
The expression of the format output is:${expression}
, remove the two big curly braces if there is only one variable without an expression.
There are also some commonly used methods, such as the length of the string, what the string starts and ends with, and so on.
command + left mouse click
, you can view the comments and usage of the method, and click in to see more string-related methods.
\n
Normally an escape character —newline
, prefix the string with ar
After that, instead of escape characters, it becomes part of the string.
3. Write at the back
Follow me, more content will continue to be output
🌹 If you like it, give it a like👍🌹
🌹 If you think you have something to gain, you can come to a wave of favorites + follow, so as not to find me next time😁🌹
🌹Welcome everyone to leave a message to exchange, criticize and correct,
Forward
Please indicate the source, thank you for your support! 🌹