Search code examples
stringjulialowercase

Julia - Check if every character in string is lowercase or space


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

Solution

  • 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