2011-12-06 42 views
-1

我具有陣列如何刪除一個元素開始以下劃線紅寶石陣列

["You purchased 2 tickets to: \n", 
"____________________________________________________________________________\n", 
"_________________ \n", 
"The Temper Trap\n", "Webster Hall, New York, NY\n", "Fri, Apr 2, 2010 07:00 PM \n", 
"\n", "Order for: Vikas Sekhri\n"] 

我想刪除下劃線(裝置的陣列的第二和第三元素)。我需要這樣的

["You purchased 2 tickets to: \n", "The Temper Trap\n", "Webster Hall, New York, NY\n", "Fri, Apr 2, 2010 07:00 PM \n", "\n", "Order for: Vikas Sekhri\n"] 

任何人都可以幫助我

+0

在詢問之前,您是否對此問題做過任何努力? –

回答

2
arr = ["You purchased 2 tickets to: \n", "____________________________________________________________________________\n", "_________________ \n", "The Temper Trap\n", "Webster Hall, New York, NY\n", "Fri, Apr 2, 2010 07:00 PM \n", "\n", "Order for: Vikas Sekhri\n"] 

arr.reject { |elt| elt.starts_with? "_" } 
0
array.reject! {|element| element =~ /_/ } 

此修改數組。如果你不想修改它,請使用reject(沒有爆炸)。