开发者

Ruby incorrect array management

I have the following p开发者_运维百科iece of code:

nonce = data.scan(/nonce="(.*)"/)

data is a string ,the matched piece of string is assigend to nonce variable which automatically becomes an Array. Now, if i

puts nonce[0]

I will get my value printed correctly:

51d8852d

but if use:

puts "final string #{md1}:#{nonce[0]}:#{md2}"

the output will be:

df49f55acfd9d21837fd840644f251b4:["51d8852d"]:3b7718806908d2a4456086be7daba94ccd36ea19fd2bfa80ae41fa8be23433b7

but there shouldn't be any brackets or duoble quotes, i should get only the array's value. It should be something like this:

df49f55acfd9d21837fd840644f251b4:51d8852d:3b7718806908d2a4456086be7daba94ccd36ea19fd2bfa80ae41fa8be23433b7

Could you please suggest me how to solve this issue? Thanks

Dawid


When you use scan with a capture group, the result is an array of arrays, so you want to use nonce[0][0]. You got confused because your first example feeds nonce[0], which is an array, to puts, which handles arrays by printing out each element. If you do puts nonce[0].class, you'll see...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜