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
“me@mine.com”.
Thanks for the info, - Dave
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
“me@mine.com”.
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
“me@mine.com”.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
“me@mine.com”.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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs