Add keyword arguments to Sprintf, similar to Python's .format()
Opened this issue · 2 comments
webvictim commented
In Python, you can use keywords and numbers in format()
to refer to the same part of a string for replacement - see https://www.digitalocean.com/community/tutorials/how-to-use-string-formatters-in-python-3#reordering-formatters-with-positional-and-keyword-arguments
You can probably do the same thing in Go, I just don't know how.
It would be useful to have similar functionality in Force too, so that rather than needing to repeat the same argument multiple times:
Sprintf("%s %s %s %s", "banana", "banana", "banana", "cabbage")
We could do things like:
# named references
Sprintf("{one} {one} {one) {two}", one="banana", two="cabbage") # prints "banana banana banana cabbage"
# numbered references
Sprintf("{0} {0} {0) {1}", "banana", "cabbage") # prints "banana banana banana cabbage"
# or maybe the ultimate, more Force-like structure...
Sprintf("{s.One} {s.One} {s.One} {s.Two}", struct s{One: "banana"; Two: "cabbage"}) # prints "banana banana banana cabbage"
This is perhaps easier in Python because of its duck typing.
klizhentas commented
Sprintf("{s.One} {s.One} {s.One} {s.Two}", _{One: "banana"; Two: "cabbage"})
This should be possible to do
webvictim commented
That would be super cool.