基本上它是Rails代码,但这里是纯Ruby问题。 要知道 - @ test.source是一些String,它可以包含' '
(空格)。其目的是删除首先出现的所有不必要的空间。例如,%some word' '' '
应该保留%some word' '
,%another word' '' '' '
应该离开%another word' '
等等。无限'while'循环
for i in [email protected]
if @test.source[i] == ' '
i=i+1
while @test.source[i] == ' '
@test.source[0...i].chop
end
else
i+=1
end
end
由于某种原因,此循环(obviosly'while')是无限的。为什么?
通常多数民众赞成用正则表达式完成的,例如:'@ test.source.gsub(/ \ s + /,'“)' – AJcodez 2013-03-07 03:12:30
正则表达式似乎是强大的工具 – 2013-03-07 03:43:22
但也删除所有换行符,如何修复? – 2013-03-07 04:03:16