I have the following:
- A
Vec<&str>
. - A
&str
that may contain$0
,$1
, etc. referencing the elements in the vector.
I want to get a version of my &str
where all occurences of $i
are replaced by the ith element of the vector. So if I have vec!["foo", "bar"]
and $0$1
, the result would be foobar
.
My first naive approach was to iterate over i = 1..N
and do a search and replace for every index. However, this is a quite ugly and inefficient solution. Also, it gives undesired outputs if any of the values in the vector contains the $
character.
Is there a better way to do this in Rust?