summaryrefslogtreecommitdiff
path: root/doc/string/getbyte.rdoc
diff options
context:
space:
mode:
Diffstat (limited to 'doc/string/getbyte.rdoc')
-rw-r--r--doc/string/getbyte.rdoc23
1 files changed, 23 insertions, 0 deletions
diff --git a/doc/string/getbyte.rdoc b/doc/string/getbyte.rdoc
new file mode 100644
index 0000000000..1d0ed2a5a4
--- /dev/null
+++ b/doc/string/getbyte.rdoc
@@ -0,0 +1,23 @@
+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 # => [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].