mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
[DOC] Tweaks for String#getbyte
This commit is contained in:
parent
d7bc1378d2
commit
6f7a4f9c96
2 changed files with 27 additions and 7 deletions
26
doc/string/getbyte.rdoc
Normal file
26
doc/string/getbyte.rdoc
Normal file
|
@ -0,0 +1,26 @@
|
|||
Returns the byte at zero-based +index+ as an integer:
|
||||
|
||||
s = 'foo'
|
||||
s.getbyte(0) # => 102
|
||||
s.getbyte(1) # => 111
|
||||
s.getbyte(2) # => 111
|
||||
|
||||
Counts backward from the end if +index+ is negative:
|
||||
|
||||
s.getbyte(-3) # => 102
|
||||
|
||||
Returns +nil+ if +index+ is out of range:
|
||||
|
||||
s.getbyte(3) # => nil
|
||||
s.getbyte(-4) # => nil
|
||||
|
||||
More examples:
|
||||
|
||||
s = 'тест'
|
||||
s.bytes # => [209, 130, 208, 181, 209, 129, 209, 130]
|
||||
s.getbyte(2) # => 208
|
||||
s = 'こんにちは'
|
||||
s.bytes # => [227, 129, 147, 227, 130, 147, 227, 129, 171, 227, 129, 161, 227, 129, 175]
|
||||
s.getbyte(2) # => 147
|
||||
|
||||
Related: see {Converting to Non-String}[rdoc-ref:String@Converting+to+Non--5CString].
|
8
string.c
8
string.c
|
@ -6685,14 +6685,8 @@ rb_str_chr(VALUE str)
|
|||
* call-seq:
|
||||
* getbyte(index) -> integer or nil
|
||||
*
|
||||
* Returns the byte at zero-based +index+ as an integer, or +nil+ if +index+ is out of range:
|
||||
* :include: doc/string/getbyte.rdoc
|
||||
*
|
||||
* s = 'abcde' # => "abcde"
|
||||
* s.getbyte(0) # => 97
|
||||
* s.getbyte(-1) # => 101
|
||||
* s.getbyte(5) # => nil
|
||||
*
|
||||
* Related: String#setbyte.
|
||||
*/
|
||||
VALUE
|
||||
rb_str_getbyte(VALUE str, VALUE index)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue