I'm trying to get rid of the brackets []
and the new line \n
from being printed.
My code looks like:
name1 = File.readlines('first.txt').sample(1)
name2 = File.readlines('middle.txt').sample(1)
name3 = File.readlines('last.txt').sample(1)
name = print (name1.strip
print name2.strip
print name3.strip)
puts name
I would like the output to look like JoshBobbyGreen
.
However, it looks like:
[\"Josh\\n\"][\"Bobby\\n\"][\"Green\\n\"]
I've tried using .gsub
, chomp
and split
but maybe I'm using them wrong.
consider also optional chomp parameter in File.readlines
File.readlines("/path/to/file", chomp: true)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With