我有一个字符串:
cipher = "0111101110010111001001010000000110101000001000111101110000110101100100001100101100000"
我想将其切片并像这样存储在数组中: [“ 01111011”,“ 10010111” ...]
我尝试了此代码,但出现错误:
“ cz.rb:16:in
<main>': undefined method
中的nil:NilClass (NoMethodError)”
i,j = 0,0
cipher_byte = []
while i < cipher.length
if i != 0 and i % 8 == 0
j+=1
end
cipher_byte[j].push(cipher[i])
p cipher_byte
i+=1
end
这是怎么了? 是红宝石。