[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Splitting a sentence with delimiter preserved

Ajithkumar Warrier

10/17/2006 8:26:00 PM

Hi,

I am a newbie and the answer to this might be too simple.
How do I improve the example below and reduce the number of passes
over the string?

string = "This is an example string. The purpose is to save the
delimiter during split. Does this work. Great!!!."

re = /(\.\s+)(\D)/
string.gsub!(re,'\1'+'#'+'\2')
b = string.split('#')
puts b

Thanks
Ajith