How do I increment/decrement a character in Ruby for all possible values?

后端 未结 4 1991
北荒
北荒 2021-01-05 00:48

I have a string that is one character long and can be any possible character value:

irb(main):001:0> \"\\x0\"
=> \"\\u0000\"

I though

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-05 01:25

    I think the most elegant method (for alphanumeric chars) would be:

    "a".tr('0-9a-z','1-9a-z0')
    

    which would loop the a through to z and through the numbers and back to a.

    I reread the question and see, that my answer has nothing to do with the question. I have no answer for manipulationg 8-bit values directly.

提交回复
热议问题