我試着寫一個應用程序,從單詞列表中移除的話:檢查數組包含字符串,不區分大小寫
puts "Words:"
text = gets.chomp
puts "Words to remove:"
remove = gets.chomp
words = text.split(" ")
removes = remove.split(" ")
words.each do |x|
if removes.include.upcase? x.upcase
print "REMOVED "
else
print x, " "
end
end
我怎麼會做出這種區分大小寫? 我試過把.upcase
放在那裏,但沒有運氣。
在哪裏?目前尚不清楚你嘗試過什麼。 if語句中的 – 2013-02-09 22:48:46
。 編輯OP – krtek 2013-02-09 22:51:40
你不需要每個元素的情況? – 2013-02-09 22:54:06