[Flutter] String of Dart data type

1. Write in front

Introduced in the previous articleDartNumeric types in the primitive data types of ,on onetypes (int and double), then continue learning nowDartThe basic syntax of the string typestring.
Flutter

[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 usageapostropheandDouble quotesYes, 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:

operation result

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:
operation result

2.3 Multi-line strings

triple quotesandDouble quotesMulti-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:

print result
three quotation markswillspaceAlso 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.
Get the specified subscript character

2.5 String Multiplication

Interestingly, strings can also be added and multiplied, but not subtracted and divided.

operation result

2.6 String format output

The format output of the string is as follows:
operation result
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.

Commonly used methods

command + left mouse click, you can view the comments and usage of the method, and click in to see more string-related methods.

\nNormally an escape character —newline, prefix the string with arAfter that, instead of escape characters, it becomes part of the string.

operation result

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,ForwardPlease indicate the source, thank you for your support! 🌹

Tags: [Flutter] String of Dart data type

Flutter flutter dart Cross-platform iOS

Related: [Flutter] String of Dart data type