HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to DartVariablesData TypesOperatorsStringsListsConditions (if / else)Loops (for / while)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables & Types
🔢 Numbers & Math
✍️ String
📚 List & Map
🔀 Condition & Loop
🧩 Function
Dart›Strings

Strings

Concatenation, interpolation, length, case conversion, and slicing methods.

Simple enough for a 5-year-old to understand

Concatenation and interpolation

You can combine strings with +, but the most readable way is embedding with $variable.

Example code
1
void main() {
2
var name = "Alex";
3
var age = 36;
4
print("$name $age years old");
Alex is 36 years old
Output / InputAlex is 36 years old
5
print("Hello " + name);
Hello Alex
Output / InputHello Alex
6
}
Output / Input
💡 Hint: You cannot combine a number with a string using +; embed with $ or use toString.

About this topic

Strings in Dart are of type String and are immutable. When you convert a string to uppercase, a new string is generated; the original remains unchanged. Therefore, you need to assign the result of string methods to a variable.

String interpolation is one of Dart's most used conveniences. You put a dollar sign in front of the variable name; if you want to write an expression, you use curly braces. Compared to concatenation with plus, it is both more readable and handles type conversion for you.

The automatic concatenation of two adjacent string literals is a convenient feature unique to Dart. You don't need to type a plus sign when splitting long strings across multiple lines in the source code.

What you will learn

  • Creating and concatenating strings
  • Template syntax and writing expressions
  • Length and search operations
  • Case conversion operations
  • Writing multi-line strings

Who is this for?

  • Those who will display text in the interface
  • Those who get errors in string concatenation
  • Developers who will process user input

When to use?

Every label shown in Flutter interfaces is a string; using interpolation makes up a large portion of the code.

For long constant strings, JSON templates, and multi-line messages, triple-quote syntax avoids escape clutter.

Common mistakes

Wrong

void main() {
  int adet = 5;
  String mesaj = "Total: " + adet;
  print(mesaj);
}

In Dart, a string and a number cannot be added directly; you get the error "The argument type 'int' can't be assigned to the parameter type 'String'". You need to convert the number to a string or use interpolation; the second approach is both shorter and safer.

Correct

void main() {
  int adet = 5;
  String mesaj = "Total: $adet";
  print(mesaj);
}

Wrong

void main() {
  var liste = [1, 2, 3];
  print("Count: $liste.length");
}

The dollar sign only takes the variable name; the dot and everything after it is considered plain text, so the list itself and then ".length" are printed to the screen. If you want to use an expression, curly braces are required.

Correct

void main() {
  var liste = [1, 2, 3];
  print("Count: ${liste.length}");
}

Wrong

void main() {
  String ad = "ayse";
  ad.toUpperCase();
  print(ad);
}

Since strings are immutable, the method does not change the original, it returns a new string. Because you didn't assign the result anywhere, the lowercase version is still printed to the screen. This is the most common mistake when working with string methods.

Correct

void main() {
  String ad = "ayse";
  ad = ad.toUpperCase();
  print(ad);
}

Frequently asked questions

How to write multi-line strings?

Triple quotes are used, and the text is preserved as is, along with line breaks. Since escape characters are not needed, it is very useful when writing JSON templates and long descriptions.

What is raw text used for?

When you put an r in front of the text, escape sequences are not processed; backslashes remain as they are. It completely eliminates escape clutter when writing file paths and regular expressions.

Is == enough to compare strings?

Yes, in Dart this operator compares the content of the strings. If you want a case-insensitive comparison, you need to convert both sides with toLowerCase.

Summary

Strings are immutable, methods return a new string.

A dollar sign is used for variables and curly braces for expressions in interpolation.

Text and numbers cannot be added directly.

Triple quotes allow for multi-line strings.

The equality operator compares the content.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code