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")
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With