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.
positions.zip(string_replace).each do |pos, str|
string[pos.to_i] = str
puts string
end
Here:
positions.each_with_index {|o, i| string[o]=replacments[i]}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With