How can I find out whether a whole string is uppercase in Elixir?
I've found a solution here. But it only addresses one letter at a time not the whole string.
You can convert the string to upper case and check if it equals the original string:
iex(1)> upcase? = fn x -> x == String.upcase(x) end
#Function<6.99386804/1 in :erl_eval.expr/5>
iex(2)> upcase?.("foo")
false
iex(3)> upcase?.("FOO")
true
iex(4)> upcase?.("π")
false
iex(5)> upcase?.("Π")
true
You can use Regex:
iex> str = "Hello World"
iex> str =~ ~r(^[^a-z]*$)
false
iex> str = "HELLO WORLD"
iex> str =~ ~r(^[^a-z]*$)
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