Format and convert

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!

About Pavel Fatin

IntelliJ Scala plugin developer (http://pavelfatin.com)
This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to Format and convert

  1. Quartz says:

    This is awesome!

  2. liango says:

    Very good, very useful to me

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">