I need to parse a string char by char, if the char is a number it should go to a array without any modification, however in case of letters they should be decoded into hexadecimals before they go to the array, for example if I have:
text = “hello5” the array should be
=> [“68”, “65”, “6c”, “6c”, “6f”, “5”]
So only letters should be converted.
I wrote the following code but don’t know what the problem with it:
text = “hello5”
number = /\d/
ntext = 
i = 0
while i < text.length
if text[i].chr=~ number
ntext << text[i].chr
ntext << text[i].chr.unpack(‘U’)[i].to_s(16)
It seems to work for the first value only text, when replaced with text or anything else I get:
“in `to_s’: wrong number of arguments (1 for 0) (ArgumentError)”
So the array ntext only stores the first converted letter, I couldn’t spot the problem?!!
Your help is really appreciated.