From: Stephen Duncan Date: 2007-04-23T11:42:50+09:00 Subject: Re: Question regarding design of the String Class ------=_Part_77813_2775977.1177296167684 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Try: b = a[1..-1] -Stephen On 4/22/07, Michael W. Ryder <_mwryder@worldnet.att.net> wrote: > > Roland Crosby wrote: > > On Apr 22, 2007, at 10:00 PM, Michael W. Ryder wrote: > > > >> Was there a reason the string class was implemented with str[i] > >> returning the code of position i in str? The reason I ask this is > >> that in other languages str[i] returns the string starting at position > >> i. For example C uses t = strcpy(str[i]) and Business Basic uses > >> S$=T$(I) to copy a string from position i. > >> I can see no way to do this in Ruby other than using something like: t > >> = str[i,9999]. It seemed strange that copying ranges of strings uses > >> the same format as C (t =strncpy(str[i],n)) but not when copying the > >> remainder. > > > > Try str[i,-1], or one of the myriad other ways to access ranges of a > > string as defined in String#[] > > > If I enter: > a = "This is a test." > b = a[1, -1] > puts b > irb returns nil. Obviously this is not what I want. If instead of -1 I > use 9999 it returns "his a test." which is what I was looking for. This > seems like a kludge and an inconsistency. Like I pointed out other > languages just use b = a[1] to get the remainder of the string instead > of 104. The string class already has methods like each_byte for > converting characters in a string to a number, so why does it need > another shortcut for something that is probably very rarely used. > > -- Stephen Duncan Jr www.stephenduncanjr.com ------=_Part_77813_2775977.1177296167684--