基本上它是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