Append or Concatenate two Strings in Dart

Welcome to tutorial on String Concatenation in Dart programming language.

Often at times, we may need to append a string to another string.

In this tutorial, we will learn how to append two strings in Dart with example programs.

To append two strings in Dart, use concatenation operator ++ accepts two strings as operands and returns concatenated string.

Example – Concatenate two Strings in Dart

In this example, we will take two Dart Strings and concatenate them using +.

Dart Program

void main(){
	
	String str1 = 'Tutorial';
	String str2 = 'Kart';
	
	//concatenate str1 and str2
	String result = str1 + str2;
	
	print(result);
}

Output

TutorialKart
ADVERTISEMENT

Example – Concatenate more than two Strings in Dart

In this example, we will take three Dart Strings and concatenate them using +. We can chain the + operator. Hence, we can concatenate more than two strings in a single statement. Please observe the below example.

Dart Program

void main(){
	
	String str1 = 'Welcome to ';
	String str2 = 'Tutorial';
	String str3 = 'Kart';
	
	//concatenate str1, str2 and str3
	String result = str1 + str2 + str3;
	
	print(result);
}

Output

Welcome to TutorialKart

Example – Concatenate String with int

You can concatenate String with other type of objects. All you need to do is convert the other type of Dart object to String using object.toString() method.

In this example, we will take a String and an int and concatenate them using +. During concatenation, we convert the int to string.

Dart Program

void main(){
	
	String str1 = 'Welcome to ';
	int n = 24;
	
	//concatenate str1 and n
	String result = str1 + n.toString();
	
	print(result);
}

Output

Welcome to 24

Conclusion

In this Dart Tutorial, we learned how to append or concatenate two ore more strings.