Reputation: 2663
Here is a string template
read from file.
Name: %s
Age: %d
After I read it from file, I want to format this string using given name and age.
var template = File("file_path").readText()
MessageFormat.format(template, "Bod", 123)
print(template)
However I cannot format template
. Its output is.
Name: %s
Age: %d
Upvotes: 0
Views: 282
Reputation: 6579
You should either use String.format
instead of MessageFormat.format
or use {0}
/{1}
instead of %s
/%d
.
Upvotes: 2