Dart – String Length
To find length of a given string in Dart, you can use length property of String class.
Syntax
The syntax to get length of string is
String.length
String.length
is a read-only property of String object, that returns an integer specifying the number of characters in the string.
Examples
Find String Length
In this example, we will take a string str
, and find its length using String.length
property.
Dart Program
void main(){ String str = 'HelloTutorialKart'; //get string length int len = str.length; print(len); }
Output
17
The length of the the given string in detailed format.
H e l l o T u t o r i a l K a r t 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Length of an empty String
In this example, we will find the length of an empty string. Of course, it would be zero. But let us verify programmatically.
Dart Program
void main(){ String str = ''; //get string length int len = str.length; print(len); }
Output
0
Conclusion
In this Dart Tutorial, we learned how to find the length of a String using the property String.length
.