Welcome to this short tutorial on Dart programming. In today's tutorial I will show you how you can add multi-line strings to your Dart program.
In Dart programming, multi-line strings can be added to the Dart program in several ways.
![]() |
Dart Programming Language |
Method 1: Using New Line '\n' Escape Sequence
// multilinestrdemo1.dart
// Dart multiline string demo program
// Using Adjacent String Literals
// Date: Tue, 04 Oct, 2022
void main() {
String string1 = 'Hi, Ankur Saxena!'
'Welcome to Dart Programming!!'
'Let us learn Dart Programming...';
print(string1);
print('-------'); // Just a horizontal line
String string2 = 'Hi, Ankur Saxena!\n'
'Welcome to Dart Programming!!\n'
'Let us learn Dart Programming...\n';
print(string2);
}
Output:
Hi, Ankur Saxena!Welcome to Dart Programming!!Let us learn Dart Programming...
-------
Hi, Ankur Saxena!
Welcome to Dart Programming!!
Let us learn Dart Programming...
Method 2: Using Triple Single Quotes
// multilinestrdemo2.dart
/*
Write a dart program to display the following string on the console screen.
Hi, Dart Programming!
Will this compile?
Oh yes it will!!
Using triple single quotes
Date: Tue, 04 Oct, 2022
*/
main(){
String string1 = '''
Hi, Dart Programming!
Will this compile?
Oh yes it will!!
''';
// printing string
print (string1);
}
Output:
Hi, Dart Programming!
Will this compile?
Oh yes it will!!
Method 3: Using Triple Double Quotes
// multilinestrdemo3.dart
/*
Write a dart program to display the following string on the console screen.
Hi, Ankur Saxena!
Welcome to Dart Programming!!
Let us learn Dart Programming...
Using triple double quotes
Date: Tue, 04 Oct, 2022
*/
main(){
String string1 = """
Hi, Ankur Saxena!
Welcome to Dart Programming!!
Let us learn Dart Programming...
""";
// printing string
print (string1);
}
Output:
Hi, Ankur Saxena!
Welcome to Dart Programming!!
Let us learn Dart Programming...
0 Comments