Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Trying to find the number lines with a determinated word
Andrés Suárez
7/16/2008 7:54:00 PM
Hi,
I'm trying to find the 'line' number where exists a predeterminated
'word':
File.open(file) do |infile|
lines = infile.readlines
lines.each { |line| puts lines.index(line) if line.split.include? word
}
end
When it finds the word, it puts 0? why?
Thanks & regards,
Andrés Suárez
--
Posted via
http://www.ruby-...
.
1 Answer
Andrés Suárez
7/16/2008 8:09:00 PM
0
Andrés Suárez wrote:
> Hi,
>
> I'm trying to find the 'line' number where exists a predeterminated
> 'word':
>
>
> File.open(file) do |infile|
> lines = infile.readlines
> lines.each { |line| puts lines.index(line) if line.split.include? word
> }
> end
>
>
> When it finds the word, it puts 0? why?
>
> Thanks & regards,
> Andrés Suárez
Yepp, I know why:
-> index returns the first match. And this is the line zero.
Regards,
Andrés
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Trying to find the number lines with a determinated word
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password