Hi,
I have this code:
<>
k = “this is a test”
l = k[/(\S+\s+){1}/].upcase
puts “first word is #{l}”
if l.eql?(“THIS”)
puts “This”
end
<>
why doesn’t it output the word “This” inside the if statement.
Thanks!
Hi,
I have this code:
<>
k = “this is a test”
l = k[/(\S+\s+){1}/].upcase
puts “first word is #{l}”
if l.eql?(“THIS”)
puts “This”
end
<>
why doesn’t it output the word “This” inside the if statement.
Thanks!
l is "THIS "
see return value on irb
k[/(\S+\s+){1}/]
k[/(\S+\s+){1}/].upcase
is this what you are trying to do??
k = “this is a test”
l = k[/(\S+\s+){1}/].upcase
puts “first word is #{l}”
if l.include?(“THIS”)
puts “This”
end
i already ave the answer…
just need to update this line
l = k[/(\S+\s+){1}/].upcase
to:
l = k[/(\S+\s+){1}/].upcase.strip to remove the ‘\n’ or \0’ character…
anyways thanks…
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs