Strings

String literals in Dart are surrounded by either single quotation marks, or double quotation marks.
'hello' is the same as "hello".
You can display a string literal with the print() function.


  1. Strings are Arrays:
  2. Like many other popular programming languages, strings in Dart are arrays.
    Square brackets can be used to access elements of the string.

    void main () {

       var txt =  "nice day" ;

       print(txt[6]);

    }


    a


  3. String Length:
  4. To get the length of a string, use .length :

    void main() {

      var txt = "nice day";

      print(txt.length);

    }


    8


  5. String concatenation:
  6. To concatenate two strings you can use the + operator :


    void main () {

      var a =  "Hello";

       var b =  "World";

       var c = a +  " " + b +  '!';

       print(c);

    }


    Hello World!



Note:

Check the Boolean Lesson to know more about "String Interpolation".

In the documentation, you can find lists of properties and methods for all these data types.
In this lesson, we don’t want to focus on them because as a beginner it’s better to discover them in the exercises.