The Extract Field refactoring lets you extract a specified value to an instance or class variable.
The animation below demonstrates how to extract a specific word from a string to an instance variable:
To extract a field:
Select a value to refactor or place a caret at a string containing the required value.
From the main menu, selectControl+Alt+F.
(Optional) If you place a caret at a place containing several expressions available for extracting, select the required expression and press Enter.
(Optional) If more than one occurrence of the expression is found, specify whether you wish to replace only the selected occurrence or all the found occurrences with the new variable:
Specify the instance/class variable name and press Enter.