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.
IntellijIDEA lets you insert a gap with concatenation intention. To do that, in your editor enter a string and press
Alt |
Enter |
Select Insert gap with concatenation ("+ +") and press
Enter |
Now you can insert a value into your string. You can evaluate the result in the Scala Console window.
For the Scala version 2.10 and later you 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
Alt |
Enter |
Enter |
You can also choose an option Convert to formatted string and get your basic Java formatted string.
You can convert your string into a multi-line string. Simply enter your string, press
Alt |
Enter |
Converting to multi-line strings removes escaped sequences such as '\\' or '\n'.
You also can convert the multi-line string into the regular string.
Press
Alt |
Enter |
Enter |
View the result.
To start entering a multi-line string, simply type triple quotes in your editor.
If you press
Enter |
The white spaces are also preserved. Please see the following example:
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.
Enter a multi-line string, press
Alt |
Enter |
You can inject language or a reference into your multi-line string literals.
Enter a multi-line string, press
Alt |
Enter |
The list of available languages opens. Choose the appropriate one and press
Enter |
To cancel the language injection, simply choose the Un-Inject Language/Reference intention.
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 Multi-line strings settings, in the main menu select
File |
Setting |
Project Settings |
Code Style |
Scala |