String = "Test string Test"
array = ["link1","link2"]
How can replace string like this ?
Output should be String = "link1 string link2"
String = "Test string Test"
array = ["link1","link2"]
How can replace string like this ?
Output should be String = "link1 string link2"
String#gsub! could return an enumerator, so this is easy:
string.gsub!("Test").each_with_index { |v, i| array[i] }
gsub earlier, why did u replace it with gsub!? It is always good to avoid gsub! as it modifies the original object.