dart

String interpolation and formation in Dart

You can perform string interpolation and formation in dart language using ${expression}. We can perform a lot of string operations using this.

void main() {
  //Concate strings using ${expression}
  var name = 'Ankit';
  print('My Name is: ${name}');
  
  //Sum using ${expression}
  var sum = sumFn(5, 10);
  print(sum);
  
  //uppercase letters using ${expression}
  var uppercaseLetters = '${"john deo".toUpperCase()}';
  print(uppercaseLetters);
}

String sumFn(int x, int y) {
  return 'Sum is: ${(x+y).toString()}';
}
Output
My Name is: Ankit
Sum is: 15
JOHN DEO
Was this helpful?