From: Siep Korteling Date: 2009-10-08T06:59:32+09:00 Subject: Re: split question Li Chen wrote: > Ryan Davis wrote: >> On Oct 7, 2009, at 14:29 , Li Chen wrote: >> >>> >>> C:\Documents and Settings\chen41\Desktop>irb >>> irb(main):001:0> s='\t\t\t\t\t\t\t\t' >>> => "\\t\\t\\t\\t\\t\\t\\t\\t" >> >> These aren't tabs. They're "\" followed by "t", you can tell because >> the "\" is backslashed, meaning it is a literal backslash. >> >> Use double quotes instead. > > Here is what I get using double quotes. I get an empty array only. > > > C:\Documents and Settings\chen41\Desktop>irb > irb(main):001:0> s="\t\t\t\t\t\t\t\t" > => "\t\t\t\t\t\t\t\t" > irb(main):002:0> s.split(/\t/) > => [] > irb(main):003:0> str.split takes two parameters: the pattern and optionally the "limit" From the docs: If the limit parameter is omitted, trailing null fields are suppressed. If limit is a positive number, at most that number of fields will be returned (if limit is 1, the entire string is returned as the only entry in an array). If negative, there is no limit to the number of fields returned, and trailing null fields are not suppressed. So s = "\t\t\t\t" s.split("\t") #all null fields #=> [] s.split("\t",-1) #=> ["", "", "", ""] hth, Siep -- Posted via http://www.ruby-forum.com/.