How to check if string is UpperCase or not in clojure?

I want to check if a string is uppercase or not. There is a character check function, but no function to check the string.

+4
source share
3 answers

Assuming you want to check that every character in String is uppercase, you can use every?as follows:

user=> (every? #(Character/isUpperCase %) "Hello")
false
user=> (every? #(Character/isUpperCase %) "HELLO")
true
+4
source

For this question, start by looking for a Java answer :)

Is there an existing library method that checks if a string is a lowercase string in Java?

Apache Commons Lang StringUtils/isAllUpperCase

(import org.apache.commons.lang3.StringUtils)

(StringUtils/isAllUpperCase "HeLLO")

, (Clojure, ClojureScript,...), , , :

(require '[clojure.string :as str])

(defn all-uppercase? [s]
  (= s (str/upper-case s)))
+4

The cuerdas library for Clojure (Script) has an upper (and locale-upper) function that can be used to check in uppercase.

https://funcool.imtqy.com/cuerdas/latest/#upper

#(= % (cuerdas/upper %))
0
source

Source: https://habr.com/ru/post/1655576/


All Articles