使用IRB,我想輸入一個多行字符串以從中剝離某些字符。 「獲取」只允許一條線 - 對於多條線有沒有類似的功能。Ruby'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
哼哼,只是打了幾次電話? – SirDarius
如果不是換行符,該方法應該如何知道何時停止閱讀? –