从红宝石字符串数组的序列获得的一组数字 [英] Obtain a set of numbers from a sequence of arrays of strings in ruby
本文介绍了从红宝石字符串数组的序列获得的一组数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串数组是如下:
B = [昨日:40,今天:20,变化:+3,changes_2:10.00%,高:30,低: 20]
我怎么会从阵列获取的设定值40,20的,+ 3,10.00%,30和20
我已经做了
C = {b.map | N | n.split()}
返回
[昨天,40] [今天,20],[变,3],[changes_2 :,10.00%],[高,30],[低,20]
解决方案块返回之前
刚指数拆分
数组:
> C = {b.map | N | n.split(:)[1]}
= GT; [40,20,+ 3,10.00%,30,20]
I have an array of strings which is as follows
b=["yesterday: 40", "today: 20", "change: +3", "changes_2: 10.00%", "high: 30", "low: 20"]
How would I obtain the set of values 40,20,+3, 10.00%, 30 and 20 from that array
I've done
c = b.map {|n| n.split(" ")}
That returns
[["yesterday:", "40"], ["today:", "20"], ["change:", "+3"], ["changes_2:", "10.00%"], ["high:", "30"], ["low:", "20"]]
解决方案
Just index the split
array before returning it in the block:
> c = b.map {|n| n.split(": ")[1]}
=> ["40", "20", "+3", "10.00%", "30", "20"]
这篇关于从红宝石字符串数组的序列获得的一组数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文