Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

String#getbyte

getbyte(index) → integer

Returns the byte at zero-based index as an integer:

Example
s = 'abcde'  # => "abcde"
s.getbyte(0) # => 97
s.getbyte(1) # => 98

Related: String#setbyte.

See also #freeze #grapheme_clusters #force_encoding #gsub also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0