String 如何比较Ocaml中的字符串

String 如何比较Ocaml中的字符串,string,ocaml,String,Ocaml,如何比较字符串?例如 “a”和“b”,因为“a”在“b”之前,所以我会放入这样的元组(“a”,“b”)。对于“c”和“b”,类似于这样的(“b”,“c”)您可以使用usal比较运算符比较字符串:=,,= 还可以使用compare函数,如果第一个字符串小于第二个字符串,则返回-1;如果第一个字符串大于第二个字符串,则返回1;如果它们相等,则返回0 # "a" < "b";; - : bool = true # "a" > "b";; - : bool = false # compare

如何比较字符串?例如
“a”和“b”,因为“a”在“b”之前,所以我会放入这样的元组
(“a”,“b”)
。对于“c”和“b”,类似于这样的
(“b”,“c”)

您可以使用usal比较运算符比较字符串:
=
=

还可以使用
compare
函数,如果第一个字符串小于第二个字符串,则返回-1;如果第一个字符串大于第二个字符串,则返回1;如果它们相等,则返回0

# "a" < "b";;
- : bool = true
# "a" > "b";;
- : bool = false
# compare "a" "b";;
- : int = -1
#“a”<“b”;;
-:bool=true
#“a”>“b”;;
-:bool=false
#比较“a”和“b”;;
-:int=-1