3

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?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
edmz
  • 3,350
  • 2
  • 22
  • 29

1 Answers1

4

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
Gible
  • 156
  • 3
  • 19
hola
  • 3,150
  • 13
  • 21