ruby - Manipulating a byte array -
I have a simple byte array
["\ x01 \ x01 \ x04 \ X00 "]
I'm not sure how can I change just the second value in the string (I know that there is only one object in the array), while keeping the object a byte array .
Some of these lines:
["\ x01 # {ARGV [0]} \ x04 \ x00"]
I think the secret is that you have nested arrays:
irb (main) : 002: 0> X = ["\ x01 \ x02 \ x01 \ x01"] = & gt; ["001 \ 002 \ 001 \ 001"]
You can index it:
irb (main): 003: 0> X [0] [1] = & gt; 2
You can assign it to:
irb (main): 004: 0> X [0] [1] = "\ x05" = & gt; "\ 005"
And what you want:
irb (main): 005: 0> X = & gt; ["001 \ 005 \ 001 \ 001"]
Comments
Post a Comment