by @kodeazy
flutter how to get last n characters of a string in flutter?
In this blog we will discuss on how to get last n
letters of a string in flutter.
To get the total count of string we use str.length
function
To get last n
letters we subtract n
with str.length
using substring
function
Below is the syntax
print(str.substring(str.length-n));
Below is the example program to print last n
letters of a string
in flutter.
void main() {
String str="hello world";
int n=5;
if(str.length>n)
print((str.substring(str.length-n)));
else
print("Exceeded the length of the string");
}
Output
world