在使用 IRB 时,我想输入一个多行字符串以从中删除某些字符。"gets" 只允许单行输入 - 是否有类似于多行输入的函数。
在IRB中,我希望输入一个多行字符串以便从中删除某些字符。"gets"只能接受单行输入,是否有类似于多行输入的函数?
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