Menu
Coddy logo textTech

String Concatenation

Part of the Fundamentals section of Coddy's Dart journey — lesson 37 of 94.

String concatenation in Dart allows you to combine multiple strings into a single string using the plus (+) operator.

Create two string variables:

void main() {
  String firstName = 'Dart';
  String lastName = 'Developer';
}

Combine the strings using the + operator:

String fullName = firstName + ' ' + lastName;
print(fullName);

When you run this code, the output will be:

Dart Developer
challenge icon

Challenge

Easy

Create a program that uses string concatenation to build a personalized greeting message.

  1. Create a string variable named firstName with the value "John"
  2. Create a string variable named lastName with the value "Doe"
  3. Create a string variable named fullName by concatenating firstName and lastName with a space in between
  4. Create a string variable named greeting by concatenating "Hello, " and fullName
  5. Create a string variable named message by concatenating greeting and "! Welcome to Dart programming."
  6. Print the message variable

Cheat sheet

String concatenation in Dart combines multiple strings using the plus (+) operator:

String firstName = 'Dart';
String lastName = 'Developer';
String fullName = firstName + ' ' + lastName;
print(fullName); // Output: Dart Developer

Try it yourself

void main() {
  // Create firstName variable with value "John"
  
  // Create lastName variable with value "Doe"
  
  // Create fullName by concatenating firstName and lastName with a space
  
  // Create greeting by concatenating "Hello, " and fullName
  
  // Create message by concatenating greeting and "! Welcome to Dart programming."
  
  // Print the message
  
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals