mirror of
https://github.com/ruby/ruby.git
synced 2026-01-26 12:14:51 +00:00
[DOC] Tweaks for String#insert
This commit is contained in:
parent
823d55a827
commit
6fbe2dd36e
16
doc/string/insert.rdoc
Normal file
16
doc/string/insert.rdoc
Normal file
@ -0,0 +1,16 @@
|
||||
Inserts the given +other_string+ into +self+; returns +self+.
|
||||
|
||||
If the given +index+ is non-negative, inserts +other_string+ at offset +index+:
|
||||
|
||||
'foo'.insert(0, 'bar') # => "barfoo"
|
||||
'foo'.insert(1, 'bar') # => "fbaroo"
|
||||
'foo'.insert(3, 'bar') # => "foobar"
|
||||
'тест'.insert(2, 'bar') # => "теbarст" # Characters, not bytes.
|
||||
'こんにちは'.insert(2, 'bar') # => "こんbarにちは"
|
||||
|
||||
If the +index+ is negative, counts backward from the end of +self+
|
||||
and inserts +other_string+ _after_ the offset:
|
||||
|
||||
'foo'.insert(-2, 'bar') # => "fobaro"
|
||||
|
||||
Related: see {Modifying}[rdoc-ref:String@Modifying].
|
||||
14
string.c
14
string.c
@ -6056,19 +6056,9 @@ rb_str_aset_m(int argc, VALUE *argv, VALUE str)
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* insert(index, other_string) -> self
|
||||
* insert(offset, other_string) -> self
|
||||
*
|
||||
* Inserts the given +other_string+ into +self+; returns +self+.
|
||||
*
|
||||
* If the Integer +index+ is positive, inserts +other_string+ at offset +index+:
|
||||
*
|
||||
* 'foo'.insert(1, 'bar') # => "fbaroo"
|
||||
*
|
||||
* If the Integer +index+ is negative, counts backward from the end of +self+
|
||||
* and inserts +other_string+ at offset <tt>index+1</tt>
|
||||
* (that is, _after_ <tt>self[index]</tt>):
|
||||
*
|
||||
* 'foo'.insert(-2, 'bar') # => "fobaro"
|
||||
* :include: doc/string/insert.rdoc
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user