mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parent
7b2bea42a2
commit
4bc6190a34
Notes:
git
2020-10-01 04:58:49 +09:00
Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
1 changed files with 57 additions and 57 deletions
114
string.c
114
string.c
|
@ -4605,71 +4605,71 @@ rb_str_aref(VALUE str, VALUE indx)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* str[index] -> new_str or nil
|
* string[index] -> new_string or nil
|
||||||
* str[start, length] -> new_str or nil
|
* string[start, length] -> new_string or nil
|
||||||
* str[range] -> new_str or nil
|
* string[range] -> new_string or nil
|
||||||
* str[regexp] -> new_str or nil
|
* string[regexp, capture = 0] -> new_string or nil
|
||||||
* str[regexp, capture] -> new_str or nil
|
* string[substring] -> new_string or nil
|
||||||
* str[match_str] -> new_str or nil
|
|
||||||
* str.slice(index) -> new_str or nil
|
|
||||||
* str.slice(start, length) -> new_str or nil
|
|
||||||
* str.slice(range) -> new_str or nil
|
|
||||||
* str.slice(regexp) -> new_str or nil
|
|
||||||
* str.slice(regexp, capture) -> new_str or nil
|
|
||||||
* str.slice(match_str) -> new_str or nil
|
|
||||||
*
|
*
|
||||||
* Element Reference --- If passed a single +index+, returns a substring of
|
* When the single \Integer argument +index+ is given,
|
||||||
* one character at that index. If passed a +start+ index and a +length+,
|
* returns the 1-character substring found in +self+ at offset +index+:
|
||||||
* returns a substring containing +length+ characters starting at the
|
* 'bar'[2] # => "r"
|
||||||
* +start+ index. If passed a +range+, its beginning and end are interpreted as
|
* Counts backward from the end of +self+ if +index+ is negative:
|
||||||
* offsets delimiting the substring to be returned.
|
* 'foo'[-3] # => "f"
|
||||||
|
* Returns +nil+ if +index+ is out of range:
|
||||||
|
* 'foo'[3] # => nil
|
||||||
|
* 'foo'[-4] # => nil
|
||||||
*
|
*
|
||||||
* In these three cases, if an index is negative, it is counted from the end
|
* When the two \Integer arguments +start+ and +length+ are given,
|
||||||
* of the string. For the +start+ and +range+ cases the starting index
|
* returns the substring of the given +length+ found in +self+ at offset +start+:
|
||||||
* is just before a character and an index matching the string's size.
|
* 'foo'[0, 2] # => "fo"
|
||||||
* Additionally, an empty string is returned when the starting index for a
|
* 'foo'[0, 0] # => ""
|
||||||
* character range is at the end of the string.
|
* Counts backward from the end of +self+ if +start+ is negative:
|
||||||
|
* 'foo'[-2, 2] # => "oo"
|
||||||
|
* Special case: returns a new empty \String if +start+ is equal to the length of +self+:
|
||||||
|
* 'foo'[3, 2] # => ""
|
||||||
|
* Returns +nil+ if +start+ is out of range:
|
||||||
|
* 'foo'[4, 2] # => nil
|
||||||
|
* 'foo'[-4, 2] # => nil
|
||||||
|
* Returns the trailing substring of +self+ if +length+ is large:
|
||||||
|
* 'foo'[1, 50] # => "oo"
|
||||||
|
* Returns +nil+ if +length+ is negative:
|
||||||
|
* 'foo'[0, -1] # => nil
|
||||||
*
|
*
|
||||||
* Returns +nil+ if the initial index falls outside the string or the length
|
* When the single \Range argument +range+ is given,
|
||||||
* is negative.
|
* derives +start+ and +length+ values from the given +range+,
|
||||||
|
* and returns values as above:
|
||||||
|
* - <tt>'foo'[0..1]</tt> is equivalent to <tt>'foo'[0, 2]</tt>.
|
||||||
|
* - <tt>'foo'[0...1]</tt> is equivalent to <tt>'foo'[0, 1]</tt>.
|
||||||
*
|
*
|
||||||
* If a +Regexp+ is supplied, the matching portion of the string is
|
* When the \Regexp argument +regexp+ is given,
|
||||||
* returned. If a +capture+ follows the regular expression, which may be a
|
* and the +capture+ argument is <tt>0</tt>,
|
||||||
* capture group index or name, follows the regular expression that component
|
* returns the first matching substring found in +self+,
|
||||||
* of the MatchData is returned instead.
|
* or +nil+ if none found:
|
||||||
|
* 'foo'[/o/] # => "o"
|
||||||
|
* 'foo'[/x/] # => nil
|
||||||
|
* s = 'hello there'
|
||||||
|
* s[/[aeiou](.)\1/] # => "ell"
|
||||||
|
* s[/[aeiou](.)\1/, 0] # => "ell"
|
||||||
*
|
*
|
||||||
* If a +match_str+ is given, that string is returned if it occurs in
|
* If argument +capture+ is given and not <tt>0</tt>,
|
||||||
* the string.
|
* it should be either an \Integer capture group index or a \String or \Symbol capture group name;
|
||||||
|
* the method call returns only the specified capture
|
||||||
|
* (see {Regexp Capturing}[Regexp.html#class-Regexp-label-Capturing]):
|
||||||
|
* s = 'hello there'
|
||||||
|
* s[/[aeiou](.)\1/, 1] # => "l"
|
||||||
|
* s[/(?<vowel>[aeiou])(?<non_vowel>[^aeiou])/, "non_vowel"] # => "l"
|
||||||
|
* s[/(?<vowel>[aeiou])(?<non_vowel>[^aeiou])/, :vowel] # => "e"
|
||||||
*
|
*
|
||||||
* Returns +nil+ if the regular expression does not match or the match string
|
* If an invalid capture group index is given, +nil+ is returned. If an invalid
|
||||||
* cannot be found.
|
* capture group name is given, +IndexError+ is raised.
|
||||||
*
|
*
|
||||||
* a = "hello there"
|
* When the single \String argument +substring+ is given,
|
||||||
|
* returns the substring from +self+ if found, otherwise +nil+:
|
||||||
|
* 'foo'['oo'] # => "oo"
|
||||||
|
* 'foo'['xx'] # => nil
|
||||||
*
|
*
|
||||||
* a[1] #=> "e"
|
* String#slice is an alias for String#[].
|
||||||
* a[2, 3] #=> "llo"
|
|
||||||
* a[2..3] #=> "ll"
|
|
||||||
*
|
|
||||||
* a[-3, 2] #=> "er"
|
|
||||||
* a[7..-2] #=> "her"
|
|
||||||
* a[-4..-2] #=> "her"
|
|
||||||
* a[-2..-4] #=> ""
|
|
||||||
*
|
|
||||||
* a[11, 0] #=> ""
|
|
||||||
* a[11] #=> nil
|
|
||||||
* a[12, 0] #=> nil
|
|
||||||
* a[12..-1] #=> nil
|
|
||||||
*
|
|
||||||
* a[/[aeiou](.)\1/] #=> "ell"
|
|
||||||
* a[/[aeiou](.)\1/, 0] #=> "ell"
|
|
||||||
* a[/[aeiou](.)\1/, 1] #=> "l"
|
|
||||||
* a[/[aeiou](.)\1/, 2] #=> nil
|
|
||||||
*
|
|
||||||
* a[/(?<vowel>[aeiou])(?<non_vowel>[^aeiou])/, "non_vowel"] #=> "l"
|
|
||||||
* a[/(?<vowel>[aeiou])(?<non_vowel>[^aeiou])/, "vowel"] #=> "e"
|
|
||||||
*
|
|
||||||
* a["lo"] #=> "lo"
|
|
||||||
* a["bye"] #=> nil
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
|
Loading…
Add table
Reference in a new issue