1
I’m riding a script that will open a text file, play the words in a array
, and then capture the word content, so far so good I can get the word content, but I need to go through all the array
and if I have the word repeated, I need to keep all the contents of that word.
Test file.txt:
a;b;c;a;d;
Code:
file = File.open('teste.txt')
#fazendo um For Linha a Linha
file.each_line do |line|
#Separando as palavras e convertendo para string
values = line.split(';').to_s()
#capturando o index da palavra que seja igual a 'a'
#idExc = Array[]
idExc = values.index(/a/)
puts values[idExc]
end
He’s only capturing the first position, but I have the letter a
repeated, I need to keep all the indexes referring to a
.
Does anyone have any idea what I can do?