我想做的比我的问题要复杂一些,但我无法用语言表达我想要做什么,而且我的术语可能是错误的。对不起。如果我之后可以编辑我的问题的标题以更好地代表我想做的事情,我会这样做。
我有一个看起来像这样的数组:
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
它删除了之后的所有内容,>
但它在第一个和第二个元素中都这样做了。