Created
March 16, 2017 16:10
-
-
Save rafael-fernandes/b0db3a607d6bf082808d719d11706634 to your computer and use it in GitHub Desktop.
Extração de palavras de um arquivo texto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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