我想要做的是稍微複雜一些,然後我的問題提出了一些問題,但我無法將它放入文字中,我想要做什麼以及我的術語可能是錯誤的。抱歉。如果我以後可以編輯我的問題的標題,以更好地表達我想要做的事情,我會這樣做。紅寶石陣列,在子陣列內刪除所有東西
我有一個數組,看起來像這樣:
array = [
["bnb ><b>(BASE CABINET)</b>", "bnb ><b>(BASE CABINET)</b>", "1", "22\"", "22\"", "22\""]
["bnb >Edgebanding (sides)", "bnb >Edgebanding (sides)", "2", "22\"", "1/2\"", "1/2\""]
["bnb >Edgebanding (top/bottom)", "bnb >Edgebanding (top/bottom)", "2", "21\"", "1/2\"", "1/2\""]
["bnb >Panel (back)", "bnb >Panel (back)", "1", "21\"", "21\"", "1/2\""]
["bnb >Panel (sides)", "bnb >Panel (sides)", "2", "21 1/2\"", "21\"", "1/2\""]
["bnb >Panel (top/bottom)", "bnb >Panel (top/bottom)", "1", "22\"", "21 1/2\"", "1/2\""]
["bnb >Top (front/back)", "bnb >Top (front/back)", "2", "22\"", "3\"", "1/2\""]
["bnb >Top (sides)", "bnb >Top (sides)", "2", "15 1/2\"", "3\"", "1/2\""]
]
我想要做的就是這個結果基本消除一切後,在每個子陣列的第一個元素>
和並去除在子陣列的第二個元素的一切>
前:
array = [
["bnb", "<b>(BASE CABINET)</b>", "1", "22\"", "22\"", "22\""]
["bnb", "Edgebanding (sides)", "2", "22\"", "1/2\"", "1/2\""]
["bnb", "Edgebanding (top/bottom)", "2", "21\"", "1/2\"", "1/2\""]
["bnb", "Panel (back)", "1", "21\"", "21\"", "1/2\""]
["bnb", "Panel (sides)", "2", "21 1/2\"", "21\"", "1/2\""]
["bnb", "Panel (top/bottom)", "1", "22\"", "21 1/2\"", "1/2\""]
["bnb", "Top (front/back)", "2", "22\"", "3\"", "1/2\""]
["bnb", "Top (sides)", "2", "15 1/2\"", "3\"", "1/2\""]
]
這裏就是我這麼遠爲代碼:
val = 0
@test_list = []
test.each do |comp|
new_list = test[val]
new_list.map! { |element| element.gsub(/\s\>.*/, '') }
comp = comp[0]
@test_list.push(new_list)
val = val + 1
end
刪除>
之後的所有內容,但它在第一個和第二個元素中都執行。
謝謝塞爾吉奧!只是傾斜新的東西:) – JoMojo 2012-04-14 02:28:47
@FrankN:究竟是什麼? :) – 2012-04-14 02:29:35
我還是很新的編程,我從來沒有使用過String#split,甚至是新的它:) – JoMojo 2012-04-14 02:32:40