special type of string replacement

L

laredotornado

Hi,

I want to insert the "​" character in between each character of
a string contained in @user.email. So if the string output were
"(e-mail address removed)", the result would be
"m​e​@​m​i​n​e​.​c​o​m".

Thanks for the info, - Dave
 
J

Joachim Glauche

laredotornado said:
Hi,

I want to insert the "​" character in between each character of
a string contained in @user.email. So if the string output were
"(e-mail address removed)", the result would be
"m​e​@​m​i​n​e​.​c​o​m".

Thanks for the info, - Dave


Something like this will do:
email = "(e-mail address removed)"
email[0..-1].gsub(/./){|c| c+"​"}+email[-1..-1]
 
S

Siep Korteling

laredotornado said:
Hi,

I want to insert the "​" character in between each character of
a string contained in @user.email. So if the string output were
"(e-mail address removed)", the result would be
"m​e​@​m​i​n​e​.​c​o​m".

Thanks for the info, - Dave

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

regards,

Siep
 
S

Sebastian Hungerecker

Joachim said:
email = "(e-mail address removed)"
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top