Using String Interpolation
Posted: Thu Jul 27, 2017 11:14 am
In computer programming, string interpolation (or variable interpolation, variable substitution, or variable expansion) is the process of evaluating a string literal containing one or more placeholders, yielding a result in which the placeholders are replaced with their corresponding values.
I was looking over the lua-users website a while back and came across this useful script that I've been using for some time. I felt it might be useful to share here so other people can find it useful too.
Both Ruby and Python have a short form for string formatting, using the % operator.
The following snippet adds a similar use of the mod operator to lua:
Example usage:
I was looking over the lua-users website a while back and came across this useful script that I've been using for some time. I felt it might be useful to share here so other people can find it useful too.
Both Ruby and Python have a short form for string formatting, using the % operator.
The following snippet adds a similar use of the mod operator to lua:
All you need to do is stick it in the scripts section somewhere.
Example usage:
In my personal opinion, it looks a bit nicer than having to regularly use string.format. I've also found it more convenient.