by @kodeazy

flutter How to get last letter of string in dart file?

Home » flutter » flutter How to get last letter of string in dart file?
  • In this blog we will discuss on how to get the the last letter of the string in flutter.
  • To get the last letter we have to identify the length of the string to fetch the last letter based on the index.
  • To get the length of the String we have length function for a String variable in dart.
  • As the String index starts from 0 we have to take String length -1 index to get the last letter of string.
  • Below is example syntax.

    print(example[example.length-1]);
  • Below is the sample program to get last letter of string based on index.

    void main() {
    String example = "Testing";
    print(example[example.length-1]);
    }

    Output

    g