I want to check whether a string is uppercase or not. There is a function to check for a character but no function to check it for a string.
For this kind of question, start by looking for the Java answer :)
Is there an existing library method that checks if a String is all upper case or lower case in Java?
In this case, my recommandation is to use Apache Commons Lang's StringUtils/isAllUpperCase
(import org.apache.commons.lang3.StringUtils)
(StringUtils/isAllUpperCase "HeLLO")
If you want a solution portable across all platforms (Clojure, ClojureScript, ...) the best strategy is probably to compare the uppercased string to the original:
(require '[clojure.string :as str])
(defn all-uppercase? [s]
(= s (str/upper-case s)))
Assuming that you want to check that every character in String is uppercase, you can use every?
like this:
user=> (every? #(Character/isUpperCase %) "Hello")
false
user=> (every? #(Character/isUpperCase %) "HELLO")
true
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