Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在 ruby 中解析以逗号分隔的参数?
例如:
$> Main.rb --xmlid 1,2,3,4,5
我想解析 1,2,3,4,5 并将其存储在一个数组中。
我怎样才能做到这一点?
谢谢。
一旦您知道列表中的索引ARGV(在本例中为 1),请使用:
ARGV
ARGV[index].split(',') #=> ["1", "2", "3", "4", "5"]