Strings to Integers

前端 未结 4 336
温柔的废话
温柔的废话 2021-01-26 09:57

Say you have the string \"Hi\". How do you get a value of 8, 9 (\"H\" is the 8th letter of the alphabet, and \"i\"

4条回答
  •  北海茫月
    2021-01-26 10:23

    You can also create an enumerable of character ordinals from a string using the codepoints method.

    string = "Hi"
    
    string.codepoints.map{|i| (i + 1).chr}.join
    => "Ij"
    

提交回复
热议问题