Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you do string interpolation with variables in Nim?

I've seen that you can interpolate strings with fmt like so:

let msg = "hello"
echo fmt"{msg}\n"

But in my case, the interpolated string is quite long. I would prefer to assign said text to a variable and then the the interpolation later, like so:

let msg = "..... long text here {place_holder1}...."
echo interpolate(msg, var1, etc)

Is this possible?

like image 888
edmz Avatar asked Oct 31 '25 03:10

edmz


1 Answers

Yes, see strutils.format.

strutils also comes with the % operator which can be used like:

let str = "$#, $#, $#"
let interp = str % ["One", "Two", "Three"]
echo(interp) # echos One, Two, Three
like image 138
hola Avatar answered Nov 04 '25 01:11

hola