[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Match all occurance of double quotes in a string

Patrick Spence

8/19/2006 4:06:00 PM

I have a string something like this...
"Now is the time for all good men to blah, blah..." - Origin unknown

I want to convert it to this...
[i]Now is the time for all good men to blah, blah...[/i] - Origin
unknown

With the first double quote converted to "[i]" and the second to "[/i]".
The occurance of the 1st double quote may or may not be at the beginning
of the string.


--
Posted via http://www.ruby-....

2 Answers

Alex Young

8/19/2006 4:11:00 PM

0

Patrick Spence wrote:
> I have a string something like this...
> "Now is the time for all good men to blah, blah..." - Origin unknown
>
> I want to convert it to this...
> [i]Now is the time for all good men to blah, blah...[/i] - Origin
> unknown
>
> With the first double quote converted to "[i]" and the second to "[/i]".
> The occurance of the 1st double quote may or may not be at the beginning
> of the string.
>
>
Rather simplistic, but should work:

string.sub(/"([^"]*)"/, '[i]\1[/i]')

--
Alex

Patrick Spence

8/19/2006 4:18:00 PM

0

Alex Young wrote:
> Patrick Spence wrote:
>>
>>
> Rather simplistic, but should work:
>
> string.sub(/"([^"]*)"/, '[i]\1[/i]')

I like simple, thanks!

--
Posted via http://www.ruby-....