Substitute the value of a variable intro the string

I have a variable: X
I have a text: " … $X…" from a text file.

What I can do, to substitute the value of variable X into the text?
I know how it can be done directly in the code: text = " bla bla bla $x … ", But if the text is been reding from the file.txt. How I can do it?

text = read(“test.txt”, String)
X = 5;
do something for substitule value of X into the text
println(text)

Thank you in advance

julia> text = "blah blah \$X blah"
"blah blah \$X blah"

julia> X = 5
5

julia> replace(text, "\$X" => "$X")
"blah blah 5 blah"

2 Likes

Thank you.

If I have many variables? Is there other way, to do it one command?

do you mean this, Replacing multiple strings errors - #4 by bkamins

1 Like

may be.
I just want to execute all $command in already existing string.