Dart – String Length

Welcome to tutorial on finding String Length.

To find length of a given string in Dart, you can use length property of String class.

The syntax to get length of String is:

String.length

String.length returns an integer specifying the number of characters in the string or otherwise called length.

Example – Find String Length

In this example, we will take a string and find its length.

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

Example – 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 it 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.