Substitute character at an index position in Ruby

indexing, position, ruby, substitution

Solution

positions.zip(string_replace).each do |pos, str|
  string[pos.to_i] = str
  puts string
end

Problem

I have a string and will like to substitute multiple characters on different positions and print that string. E.g. Here I like to substitute string at positions with string_replace. ``` string = "AGACACTTTATATGTAT" positions = ["2", "5", "8", "10"] string_replace = ["T", "A", "G", "G"] ``` The output I need is this => "AGTCAATTGAGATGTAT" I tried this but with no success: ``` positions.zip(string_replace).each do |pos, str| string.gsub!(/#{string}[#{pos}]/, '#{str}') puts string end ``` Any assistance will be appreciated.

Original source