我想知道是否有可能刪除一個字符串,因爲它被放入和數組?這是我工作的代碼:刪除文本一旦放入數組
def footnotes(text)
file = File.open(text, "r+")
contents = file.read
notes = []
search = contents.scan(/\\f.*?\\f\*/).each do |find|
notes.push(find)
end
result = notes.each do|note| puts "#{note}\n"
end
fn = File.open('footnotes.txt', 'w+')
fn.puts(result)
fn.close
file.close
end
我希望我會能夠在文本中刪除\\f.*?\\f\*
一旦它發現並放入數組
所以你想刪除數組中的每一個字符串? – 2015-02-09 11:31:57
不,我需要刪除文本中的匹配文本,因爲它被放入數組中。所以例如。一旦在字符串「我有一隻貓」中找到「貓」,它將刪除字符串中的匹配,但將它保留在數組中,所以結果將是數組:[「貓」]字符串:「我有一個」 – Rebs 2015-02-09 11:37:43