Skip to content
Advertisement

Extracting multiple string to constant in Intellij IDEA

In my code, there are a lot of strings appeared in the following structure:

JavaScript

I would like to extract the string key to a constant. However, doing this one by one will take forever…So, is there a better way to achieve this?

Advertisement

Answer

No idea in Intellij, but if your lines are genuinely that simple, you can do it with a bit of command line fu:

JavaScript

to get the string declarations:

JavaScript

Then

JavaScript

to replace the map.put lines.

JavaScript

Copy and paste from the command line into your file; or use a text editor which lets you do it inline (e.g. in Vim, shift+V to select the lines, then :! and enter the awk command from above).

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement