Format and convert

Posted on by Pavel Fatin

The truth is that programmers often need to embed dynamic variables into static string patterns. To accomplish this feat we used to write something like:

or even

A good news is that Scala 2.10 brings a shiny new string interpolation:

The new syntax is more concise, offers more static checking and provides a better runtime performance.

To facilitate the transition, Scala plugin introduced a new group of intentions to easily convert between all the variants of string formatting:





In addition, we now have a complete format string and argument verification in the following places:

  • "…".format(…)
  • ….formatted("…")
  • String.format("…", …)
  • printf("…", …)
  • System.out.printf("…", …)
  • Interpolated strings

The verification is even more fine-grained than the similar one in Java:

All the functionality is already available in the Scala plugin nightly builds (Nika | Leda).

Enjoy!

Comments below can no longer be edited.

2 Responses to Format and convert

  1. Quartz says:

    July 13, 2012

    This is awesome!

  2. liango says:

    August 1, 2012

    Very good, very useful to me