How do I accept only letters in the Ruby entry?

Asked

Viewed 49 times

-2

Given a string, you have to take only uppercase and lowercase letters. And in the output show them. How can I achieve this result?

1 answer

1

class String
  def pega_maiusculas
    self.scan /\p{Upper}/
  end
  def pega_minusculas
    self.scan /\p{Lower}/
  end
end

str = "Teste TeStE tEsTe"
maiusculas = str.pega_maiusculas
minusculas = str.pega_minusculas

puts maiusculas
puts "\n"
puts minusculas

Browser other questions tagged

You are not signed in. Login or sign up in order to post.