Special type of string replacement

Hi,

I want to insert the “​” character in between each character of
a string contained in @user.email. So if the string output were
[email protected]”, the result would be
“m​e​@​m​i​n​e​.​c​o​m”.

Thanks for the info, - Dave

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
[email protected]”, the result would be
“m​e​@​m​i​n​e​.​c​o​m”.

Thanks for the info, - Dave

Something like this will do:
email = “[email protected]
email[0…-1].gsub(/./){|c| c+“​”}+email[-1…-1]

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
[email protected]”, the result would be
“m​e​@​m​i​n​e​.​c​o​m”.

Thanks for the info, - Dave

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

regards,

Siep

Joachim G. wrote:

email = “[email protected]
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