Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Re: Question about split method
Phy Prabab
2/25/2008 7:02:00 PM
how about spliting across the the possible
punctuation? e.g. "This is a sentence. This is a
sentence? This is a
sentence!".strip.split(/(\.|\?|\!)/)
--- Glenn <glenn_ritz@yahoo.com> wrote:
> Hello,
>
> I'm wondering if there is a method for the String
> class that splits a string on some characters and
> keeps the split characters in the elements of the
> resulting array?
>
> The split method returns an array in this example:
>
> p "This is a sentence. This is a sentence! This is a
> sentence?".strip.split(/\.|\?|\!/)
>
>
> ["This is a sentence", " This is a sentence", " This
> is a sentence"]
>
> The three sentences in the above string have very
> different meanings, but loose those meanings without
> the punctuation, so I'd like to keep the
> punctuation. I'd like a method that keeps the split
> characters, and returns this array:
>
> ["This is a sentence.", " This is a sentence!", "
> This is a sentence?"]
>
> Does such an array exist? If not, would it be
> possible to modify the split method to produce
> that result?
>
> I'm running Ruby 1.8.6 on Windows.
>
> Thanks for your help.
>
>
____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search.
http://tools.search.yahoo.com/newsearch/category.php?categor...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: Question about split method
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password