新手问题 字符串数组之间的转换

easonlovejiven · February 02, 2015 · Last by easonlovejiven replied at February 02, 2015 · 3592 hits

怎样将字符串:str = "'a','b','c','d' ,'e'','f','g'" => ary = ['a','b','c','d',......]

'abc'.split('')

首先要感谢您。。但是这个我已经尝试不太对啊同事!

str.split(',')

首先要感谢您的回答。。但是这个我已经尝试不太对啊同事!

# 转换成数组
b = a.split(/'*,*'/).select {|d| d != ""}
# 转换成字符
"'#{b.join("','")}'"

str.scan('\w')或者str.scan(/(?<=').*(?=')/)

You need to Sign in before reply, if you don't have an account, please Sign up first.