String Properties in Dart Programming


Strings in Dart have certain properties attached to them. These properties come in handy in different use cases.

The most common used string properties are −

  • hashCode

  • isEmpty

  • isNotEmpty

  • length

  • runes

In this article, we will explore all the above mentioned properties of a string.

hashCode

The hashCode property of a string is used to print the hashCode number of the specific string on which it is called.

Example

Consider the example shown below −

 Live Demo

void main(){
   String name = "Tutorials Point";
   print(name.hashCode);
}

Output

147510269

isEmpty

The isEmpty property of a string returns true when the string is an empty string.

Example

Consider the example shown below −

 Live Demo

void main(){
   String name = "Tutorials Point";
   print(name.isEmpty);
   name = "";
   print(name.isEmpty);
}

Output

false
true

isNotEmpty

The isNotEmpty property of a string returns true when the string is not empty.

Example

Consider the example shown below −

 Live Demo

void main(){
   String name = "Tutorials Point";
   print(name.isNotEmpty);
   name = "";
   print(name.isNotEmpty);
}

Output

true
false

length

The length property of a string is used to print the number of characters that are present inside the string.

Example

Consider the example shown below −

 Live Demo

void main(){
   String name = "Tutorials Point";
   print(name.length);
}

Output

15

runes

The runes property is used to print the number of Unicode code-points present in the string.

Example

Consider the example shown below −

 Live Demo

void main(){
   String name = "Tutorials Point";
   print(name.runes);
}

Output

(84, 117, 116, 111, 114, 105, 97, 108, 115, 32, 80, 111, 105, 110, 116)

Updated on: 24-May-2021

166 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements