Menu
Coddy logo textTech

Strings

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

Strings in Dart represent text data, enclosed in single or double quotes.

void main() {
  String greeting = 'Hello, Dart!';
  print(greeting);
}

Both quote types work:

void main() {
  String withSingleQuotes = 'Learning Dart';
  String withDoubleQuotes = "Programming is fun";
  
  print(withSingleQuotes);
  print(withDoubleQuotes);
}

Concatenate strings with +:

void main() {
  String firstName = 'Dart';
  String lastName = 'Developer';
  
  // Combine strings
  String fullName = firstName + ' ' + lastName;
  print(fullName);
}
challenge icon

Challenge

Beginner

Create a Dart program that works with strings:

  1. Declare a string variable named cityName and set it to "New York"
  2. Declare a string variable named countryName and set it to "USA"

Your output must match this exact format (use these exact English labels):

City: New York<br>Country: USA

Cheat sheet

Strings in Dart represent text data, enclosed in single or double quotes:

String greeting = 'Hello, Dart!';
String message = "Programming is fun";

Concatenate strings with +:

String firstName = 'Dart';
String lastName = 'Developer';
String fullName = firstName + ' ' + lastName;

Try it yourself

void main() {
  // Declare your variables here
  String cityName = ?;
  String countryName = ?;
  
  // Print the variables with labels
  print("City: " + cityName);
  print("Country: " + countryName);
}
quiz iconTest yourself

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

All lessons in Fundamentals