substring

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

substring

Mark Volkmann
I can't find a method to give me a substring of a String from a given  
index to the end. The copyFrom:to: method requires telling it the end.  
Does a method exist where you only specify the starting point? I know  
I could write it myself, but I don't want to do that if it's already  
there.

---
Mark Volkmann




_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: substring

Randal L. Schwartz
>>>>> "Mark" == Mark Volkmann <[hidden email]> writes:

Mark> I can't find a method to give me a substring of a String from a given
Mark> index to the end. The copyFrom:to: method requires telling it the end.
Mark> Does a method exist where you only specify the starting point? I know I
Mark> could write it myself, but I don't want to do that if it's already
Mark> there.

Look at all senders of #copyFrom:to: in the SequenceableCollection class.
The one you want may already be there, just named a bit odd.

In fact, there's #allButFirst: which seems to be what you want, except
that it's off by one.

That is,

   'abcde' allButFirst: 2

would return 'cde'.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: substring

tblanchard
What's wrong with last:  ?

'abcdefg' last: 4

yields 'defg'

There's also first:

On Oct 3, 2008, at 5:52 PM, Randal L. Schwartz wrote:

>>>>>> "Mark" == Mark Volkmann <[hidden email]> writes:
>
> Mark> I can't find a method to give me a substring of a String from  
> a given
> Mark> index to the end. The copyFrom:to: method requires telling it  
> the end.
> Mark> Does a method exist where you only specify the starting point?  
> I know I
> Mark> could write it myself, but I don't want to do that if it's  
> already
> Mark> there.
>
> Look at all senders of #copyFrom:to: in the SequenceableCollection  
> class.
> The one you want may already be there, just named a bit odd.
>
> In fact, there's #allButFirst: which seems to be what you want, except
> that it's off by one.
>
> That is,
>
>   'abcde' allButFirst: 2
>
> would return 'cde'.
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503  
> 777 0095
> <[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
> See http://methodsandmessages.vox.com/ for Smalltalk and Seaside  
> discussion
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners