From: Jeremy McAnally Date: 2007-12-06T20:48:00+09:00 Subject: Re: if /hello/ =~line You can use string interpolation like you can with double quoted strings. var1 = "hello" File.foreach "file.txt" do |line| if /#{var1}/ =~ line puts "found it" break end end --Jeremy On 12/6/07, Peter Loftus wrote: > Got help with this code earlier its just checking a file for a line > > Im really new to ruby ive used java and C before > > just wondering what do i put in if i want to use a variable that is > holding the string eg VAR1 = "hello" > > File.foreach "file.txt" do |line| > if /hello/ =~ line > puts "found it" > break > end > end > -- > Posted via http://www.ruby-forum.com/. > > -- http://www.jeremymcanally.com/ My books: Ruby in Practice http://www.manning.com/mcanally/ My free Ruby e-book http://www.humblelittlerubybook.com/ My blogs: http://www.mrneighborly.com/ http://www.rubyinpractice.com/