Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dart String Comparator

Tags:

dart

What is the best way to compare Strings in Dart? The String class does not contain an equals method. Is == recommended?

For example:

String rubi = 'good'; String ore = 'good';  rubi == ore; 
like image 888
Tiago Pertile Avatar asked Apr 27 '13 18:04

Tiago Pertile


People also ask

How do you compare Dart strings?

You can use compareTo to compare strings. String rubi = 'good'; String ore = 'good'; rubi. compareTo(ore) == 0; You need to check for NULL values though.

How do you compare two characters in darts?

You can use compareTo to compare them. Show activity on this post. Dart doesn't have a 'char' or 'character' type. You can get the UTF-16 character code from any point in a string, and compare that.

What is a string comparator?

The Java String compareTo() method is used for comparing two strings lexicographically. Each character of both the strings is converted into a Unicode value for comparison. If both the strings are equal then this method returns 0 else it returns positive or negative value.


1 Answers

Yes, == is the way to test if two Strings are equal (contain exclusively the same sequence of characters). The last line of your code evaluates to true.

like image 111
Darshan Rivka Whittle Avatar answered Oct 18 '22 20:10

Darshan Rivka Whittle