The syntax of String.length property is:
int length
This length property of String returns the length of the string.
String.length returns value of type int
.
In this example,
str1
with the value 'Hello, world!'.length
property of str1
to get its length.str1
is printed to standard output.void main() {
String str1 = 'Hello, world!';
int length1 = str1.length;
print('Length of str1: $length1');
}
Length of str1: 13
In this example,
str2
with the value 'ABCDEF'.length
property of str2
to get its length.str2
is printed to standard output.void main() {
String str2 = 'ABCDEF';
int length2 = str2.length;
print('Length of str2: $length2');
}
Length of str2: 6
In this example,
str3
with the value 'Lorem ipsum dolor sit amet'.length
property of str3
to get its length.str3
is printed to standard output.void main() {
String str3 = 'Lorem ipsum dolor sit amet';
int length3 = str3.length;
print('Length of str3: $length3');
}
Length of str3: 27
In this Dart tutorial, we learned about length property of String: the syntax and few working examples with output and detailed explanation for each example.