开发者

Write to file and keep the same formatting as the terminal does with Ruby

I am working with a file that has numbers and let开发者_如何学编程ters in it. I managed to remove the letters with regexps, but when I try to output the file with just the numbers in using:

matchIt = File.open('numbers.txt', 'a') {|f| f.write(string[i]) }

they appear attached together like this:

1613714531731413747

When I run a ruby script from the terminal, I normally type:

ruby script.rb > numbers.txt

which would then format the numbers downward:

1

2

3

4

5

Can I do the same thing with ruby using the command I have above?


If you're looking to print a new line for each number, just use f.puts instead of f.write.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜