How do I check if every character in a string is lowercase or space?
"this is all lowercase" -> true
"THIS is Some uppercase " -> false
"HelloWorld " -> false
"hello world" -> true
You could use the predicate/itr method of all
(docs:
julia> f(s) = all(c->islower(c) | isspace(c), s);
julia> f("lower and space")
true
julia> f("mixED")
false
You could also use regexes. The regex ^[a-z\s]+$
checks if you only have lowercase letters or spaces from start to end in your string.
julia> f(s)=ismatch(r"^[a-z\s]+$",s)
f (generic function with 1 method)
julia> f("hello world!")
false
julia> f("hello world")
true
julia> f("Hello World")
false
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