D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
String
/
Filename :
split-i.ri
back
Copy
U:RDoc::AnyMethod[iI" split:ETI"String#split;TF:publico:RDoc::Markup::Document:@parts[(o:RDoc::Markup::Paragraph; [I".Returns an array of substrings of +self+ ;TI"-that are the result of splitting +self+ ;TI"Aat each occurrence of the given field separator +field_sep+.;To:RDoc::Markup::BlankLine o; ; [I"%When +field_sep+ is <tt>$;</tt>:;T@o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0; [o; ; [I"2If <tt>$;</tt> is +nil+ (its default value), ;TI"Mthe split occurs just as if +field_sep+ were given as a space character ;TI"(see below).;T@o;;0; [o; ; [I"!If <tt>$;</tt> is a string, ;TI"Gthe split occurs just as if +field_sep+ were given as that string ;TI"(see below).;T@o; ; [I"NWhen +field_sep+ is <tt>' '</tt> and +limit+ is +0+ (its default value), ;TI"5the split occurs at each sequence of whitespace:;T@o:RDoc::Markup::Verbatim; [ I"?'abc def ghi'.split(' ') => ["abc", "def", "ghi"] ;TI"B"abc \n\tdef\t\n ghi".split(' ') # => ["abc", "def", "ghi"] ;TI"?'abc def ghi'.split(' ') => ["abc", "def", "ghi"] ;TI",''.split(' ') => [] ;T:@format0o; ; [ I">When +field_sep+ is a string different from <tt>' '</tt> ;TI"and +limit+ is +0+, ;TI"9the split occurs at each occurrence of +field_sep+; ;TI"0trailing empty substrings are not returned:;T@o;; [I"7'abracadabra'.split('ab') => ["", "racad", "ra"] ;TI"7'aaabcdaaa'.split('a') => ["", "", "", "bcd"] ;TI"&''.split('a') => [] ;TI"5'3.14159'.split('1') => ["3.", "4", "59"] ;TI"B'!@#$%^$&*($)_+'.split('$') # => ["!@#", "%^", "&*(", ")_+"] ;TI"5'тест'.split('т') => ["", "ес"] ;TI"@'こんにちは'.split('に') => ["こん", "ちは"] ;T;0o; ; [I"6When +field_sep+ is a Regexp and +limit+ is +0+, ;TI"5the split occurs at each occurrence of a match; ;TI"0trailing empty substrings are not returned:;T@o;; [ I"8'abracadabra'.split(/ab/) # => ["", "racad", "ra"] ;TI"5'aaabcdaaa'.split(/a/) => ["", "", "", "bcd"] ;TI"O'aaabcdaaa'.split(//) => ["a", "a", "a", "b", "c", "d", "a", "a", "a"] ;TI"4'1 + 1 == 2'.split(/\W+/) # => ["1", "1", "2"] ;T;0o; ; [I"EIf the \Regexp contains groups, their matches are also included ;TI"in the returned array:;T@o;; [I"@'1:2:3'.split(/(:)()()/, 2) # => ["1", ":", "", "", "2:3"] ;T;0o; ; [I"'As seen above, if +limit+ is +0+, ;TI"0trailing empty substrings are not returned:;T@o;; [I"5'aaabcdaaa'.split('a') => ["", "", "", "bcd"] ;T;0o; ; [I"FIf +limit+ is positive integer +n+, no more than <tt>n - 1-</tt> ;TI"@splits occur, so that at most +n+ substrings are returned, ;TI"0and trailing empty substrings are included:;T@o;; [ I"2'aaabcdaaa'.split('a', 1) # => ["aaabcdaaa"] ;TI"5'aaabcdaaa'.split('a', 2) # => ["", "aabcdaaa"] ;TI">'aaabcdaaa'.split('a', 5) # => ["", "", "", "bcd", "aa"] ;TI"D'aaabcdaaa'.split('a', 7) # => ["", "", "", "bcd", "", "", ""] ;TI"D'aaabcdaaa'.split('a', 8) # => ["", "", "", "bcd", "", "", ""] ;T;0o; ; [I">Note that if +field_sep+ is a \Regexp containing groups, ;TI"Ptheir matches are in the returned array, but do not count toward the limit.;T@o; ; [I"IIf +limit+ is negative, it behaves the same as if +limit+ was zero, ;TI"%meaning that there is no limit, ;TI"0and trailing empty substrings are included:;T@o;; [I"E'aaabcdaaa'.split('a', -1) # => ["", "", "", "bcd", "", "", ""] ;T;0o; ; [I";If a block is given, it is called with each substring:;T@o;; [I"9'abc def ghi'.split(' ') {|substring| p substring } ;T;0o; ; [I"Output:;T@o;; [I""abc" ;TI""def" ;TI""ghi" ;T;0o; ; [I"2Related: String#partition, String#rpartition.;T: @fileI" string.c;T:0@omit_headings_from_table_of_contents_below0I"ksplit(field_sep = $;, limit = 0) -> array split(field_sep = $;, limit = 0) {|substring| ... } -> self ;T0[ I"(p1 = v1, p2 = v2);T@FI"String;TcRDoc::NormalClass00