[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

special type of string replacement

(D. Alvarado)

2/15/2008 4:19:00 PM

Hi,

I want to insert the "​" character in between each character of
a string contained in @user.email. So if the string output were
"me@mine.com", the result would be
"m​e​@​m​i​n​e​.​c​o​m".

Thanks for the info, - Dave
3 Answers

Joachim Glauche

2/15/2008 4:34:00 PM

0

laredotornado wrote:
> Hi,
>
> I want to insert the "​" character in between each character of
> a string contained in @user.email. So if the string output were
> "me@mine.com", the result would be
> "m​e​@​m​i​n​e​.​c​o​m".
>
> Thanks for the info, - Dave


Something like this will do:
email = "me@mine.com"
email[0..-1].gsub(/./){|c| c+"​"}+email[-1..-1]
--
Posted via http://www.ruby-....

Siep Korteling

2/15/2008 4:37:00 PM

0

laredotornado wrote:
> Hi,
>
> I want to insert the "​" character in between each character of
> a string contained in @user.email. So if the string output were
> "me@mine.com", the result would be
> "m​e​@​m​i​n​e​.​c​o​m".
>
> Thanks for the info, - Dave

p "astring".split("").join("​")

regards,

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

Sebastian Hungerecker

2/15/2008 4:52:00 PM

0

Joachim Glauche wrote:
> email = "me@mine.com"
> email[0..-1].gsub(/./){|c| c+"​"}+email[-1..-1]

I guess you want that to be email[0..-2] not email[0..-1] (otherwise you'll
have the last character twice). Anyway, here's my gsub solution:
email.gsub(/(.)(?=.)/, '\1​')


HTH,
Sebastian
--
Jabber: sepp2k@jabber.org
ICQ: 205544826