Substitute tokens in a String
From CodeCodex
Implementations[edit]
Java[edit]
Object[] params = new Object[]{"hello", "!"}; String msg = MessageFormat.format("{0} world {1]", params); // hello world !
java.text.MessageFormat is a very powerful API, you should study the javadoc to see all the possibilities.
Ruby[edit]
params = ["hello", "!"] msg = "#{params[0]} world #{params[1]}" # or msg = format("%s world %s", *params)