问题
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?
回答1:
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
来源:https://stackoverflow.com/questions/58739226/how-do-you-do-string-interpolation-with-variables-in-nim