Related Articles

Related Articles

Strings in Dart
  • Last Updated : 11 Jun, 2020

A Dart string is a sequence of UTF-16 code units. With the same rule as that of Python you can use either single or double quotes to create a string. The string starts with the datatype Var

var string = "I love GeeksforGeeks";
var string1 = 'GeeksforGeeks is a great platform for upgrading skills';

Both the strings above when running on a Dart editor will work perfectly.

You can put the value of an expression inside a string by using ${expression}. It will help the strings to concatenate very easily. If the expression is an identifier, you can skip the {}

Dart

filter_none

edit
close

play_arrow

link
brightness_4
code

void main () {
var string = 'I do coding';
var string1 = '$string on Geeks for Geeks';
print (string1);
}

chevron_right




Output :

I do coding on Geeks for Geeks.

Dart also allows us to concatenate the string by + operator as well as we can just separate the two strings by Quotes. The concatenation also works over line breaks which is itself a very useful feature.

Dart

filter_none

edit
close

play_arrow

link
brightness_4
code

var string = 'Geeks''for''Geeks';
var str = 'Coding is ';
var str1 = 'Fun';
print (string); 
print (str + str1);

chevron_right


Output :

GeeksforGeeks
Coding is Fun

We can also check whether two strings are equal by == operator. It compares every element of first string with the every element of second string.

Dart

filter_none

edit
close

play_arrow

link
brightness_4
code

void main(){
var str = 'Geeks';
var str1 = 'Geeks';
if (str == str1){
print (True);
}
}

chevron_right


Output : 

True

We can also create a raw string by prefixing it with r  

var str = r' Code and repeat ' ;



My Personal Notes arrow_drop_up
Recommended Articles
Page :