【发布时间】:2012-11-30 04:01:42
【问题描述】:
使用 IRB,我想输入一个多行字符串,以便从中删除某些字符。 “获取”只允许单行 - 多行是否有类似的功能。
ASCII_project.rb(main):002:0* puts = "What's the text you want to strip?"
=> "What's the text you want to strip?"
ASCII_project.rb(main):003:0> str = gets
我现在想粘贴一段文本 - 因为新行它不起作用。这就是为什么我要收集多行
这里是代码
# encoding: CP850
puts = "What's the text you want to strip?"
str = gets
str.gsub!(/\P{ASCII}/, '')
puts str
【问题讨论】:
-
哼,只是callget了几次?
-
如果不是换行符,该方法应该如何知道何时停止阅读?