String Interpolation #

It is used to Insert variable in the String. You can call this as alternative to string concatenation.

If we have to concat two string or two string type variable. We use plus(+) to concat that in dart.

Example 1 #

Let’s concat two String variable.

int main(){
    String first_name = "Nitish";
    String last_name = "Kumar";
    String full_name = "$first_name $kulast_namemar";
    print(full_name); // Nitish Kumar

Example 2 #

Let’s concat two variables, one string and other integer.

In String interpolation we can use any type of variable. It convert all variable to the string before concatenating.

int main(){
    String first_name = "Nitish";
    int age = 20;
    String intro = "I am $first_name and my age is $age";
    print(full_name); // I am Nitish and my age is 20
comments powered by Disqus