Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

IntellijIDEA lets you add different intentions for strings and perform different actions with strings in Scala. IntellijIDEA also supports a Scala multi-line strings feature. This feature lets you format literals and helps your code to look more orderly.

1. How to Insert Gap with concatenation into a String

IntellijIDEA lets you insert a gap with concatenation intention. To do that, in your Editor enter a string and press

span
classshortcut
Alt
+
span
classshortcut
Enter
. The list of appropriate intentions opens.

...


Now you can insert a value into your string. You can evaluate the result in Scala Console.

2. How to Convert a String Concatenation into Interpolated String

For the Scala version 2.10 and later you also have the ability to convert a string concatenation into the interpolated string.
To do that, select a value with concatenation in your string and press

span
classshortcut
Alt
+
span
classshortcut
Enter
. The list of appropriate intentions opens. (You can also choose an option Convert to formatted string and get your basic Java formatted string.)

Select Convert to interpolated string, press
span
classshortcut
Enter
and view the result.



3. How to Convert a Strings into a Multi-line String

You can convert your string into a multi-line string. Simply press

span
classshortcut
Alt
+
span
classshortcut
Enter
and select Convert to """string""" option in the drop-down list of intentions.

...


The white spaces are also preserved. Please see the following example:


4. How to Insert a Replace Intention

The .replace("\r"," ") intention lets you keep the carret in the correct place on the next line in the multi-line strings regardless of what operating system you have at the moment.


5. How to Edit Multi-line Strings Settings

You can set a different format for multi-line strings options such as Margin char indent or Margin Char. You can also disable a multi-line strings support.
To open the appropriate window, in the main menu select

span
classshortcut
File
span
classshortcut
Setting
span
classshortcut
Project Settings
span
classshortcut
Code Style
span
classshortcut
Scala
. On the Scala page select the Multi-line strings tab.