Skip to content

Instantly share code, notes, and snippets.

@rafael-fernandes
Created March 16, 2017 16:10
Show Gist options
  • Save rafael-fernandes/b0db3a607d6bf082808d719d11706634 to your computer and use it in GitHub Desktop.
Save rafael-fernandes/b0db3a607d6bf082808d719d11706634 to your computer and use it in GitHub Desktop.
Extração de palavras de um arquivo texto
TIPO_UTIL_CHARS = "abcdefghijklmnopqrstuvwxyz"
class String
def tipo_util?
TIPO_UTIL_CHARS.include? self
end
end
texto = File.read('ps.txt')
palavra = ""
lista_de_palavras = []
texto.chars.map(&:downcase).each do |char|
if char.tipo_util?
palavra = palavra + char
elsif char == " "
lista_de_palavras << palavra
palavra = ""
end
end
print lista_de_palavras.uniq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment