Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out if whole string is upper case in Elixir? [closed]

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.

like image 255
J. Doe 2018 Avatar asked Jan 03 '18 10:01

J. Doe 2018


2 Answers

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
like image 69
Dogbert Avatar answered Oct 09 '22 07:10

Dogbert


You can use Regex:

iex> str = "Hello World"
iex> str =~ ~r(^[^a-z]*$)
false

iex> str = "HELLO WORLD"
iex> str =~ ~r(^[^a-z]*$)
true
like image 24
Siraj Kakeh Avatar answered Oct 09 '22 08:10

Siraj Kakeh