Clojure - 字串比較



當‘x’在邏輯上“小於”、“等於”或“大於”‘y’時,返回負數、零或正數。它類似於 Java 中的 x.compareTo(y),但它也適用於 nil,並且能夠以型別無關的方式比較數字和集合。

語法

以下是語法。

(compare x y)

引數 − 其中 x 和 y 是需要比較的兩個字串。

返回值 − 當‘x’在邏輯上“小於”、“等於”或“大於”‘y’時,返回負數、零或正數。

示例

以下是 Clojure 中字串格式化的示例。

(ns clojure.examples.hello
   (:gen-class))
(defn hello-world []
   (println (compare "Hello" "hello"))
   (println (compare "Hello" "Hello")))
(hello-world)

輸出

以上程式產生以下輸出。

-32
0
clojure_strings.htm
廣告
© . All rights reserved.