Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I compare string in Ocaml

Tags:

string

ocaml

How do I go about comparing strings? For example "a" and "b", since "a" comes before "b" then I would put in a tuple like this("a","b"). For "c" and "b", it would be like this ("b","c")

like image 385
john maniaci Avatar asked Jan 04 '23 07:01

john maniaci


1 Answers

You can compare strings with the usal comparison operators: =, <>, <, <=, >, >=.

You can also use the compare function, which returns -1 if the first string is less than the second, 1 if the first string is greater than the second, and 0 if they are equal.

# "a" < "b";;
- : bool = true
# "a" > "b";;
- : bool = false
# compare "a" "b";;
- : int = -1
like image 80
Jeffrey Scofield Avatar answered Jan 21 '23 20:01

Jeffrey Scofield