For example 开发者_开发百科I have file file_name
with such content:
Just some text,
nothing more
Then I run kind of this code:
lines = File.open(file_name, "r").readlines
# do something do with lines
File.open(file_name, "w").write(lines)
I'll get this text
"Just some text,"
"nothing more"
How to prevent "
sign here? I want text without quotes. Thanks
If you are using ruby 1.9.2, Array#to_s
works like Array#inspect
. Try this instead (some style tweaks thrown in):
lines = File.readlines(file_name)
File.open(file_name, 'w') { |f| f.write(lines.join) }
If you are only concerned with the quotes enclosing each line
okay, let's try that again
lines.gsub(/^"|"$/, '')
should work
精彩评论