From: Wayne Brissette Date: 2012-09-24T21:12:59+09:00 Subject: Re: Insert at index On Sep 24, 2012, at 6:34 AM, Geena Tho wrote: > Hi, > Is there any alternative for insert in string. I need to insert > different > characters at different indices using a loop, but since insert modifies > the string it goes wrong. > Please help. I'm not sure I understand the full question, but since you are looping, one way to do this: new_variable = old_string.split(/(your value here)/) new_variable is an array so then you can do this: new_variable.each_with_index do | value, index | # Your code here to make the change # then just substitute the new change like this: new_variable(index) = (your new code/variable) end # Then just put your array back into a string using .join. Wayne