Skip to main content

Extract String to Resource (replace all)

Extracts the string at the caret into a resource file, and replaces all occurrences of this string with a reference to the resource string.

#Availability

Available from the context menu or via shortcuts:

  • When the caret is on a string, provided that this string occurs more than once within the current member. This string should not be assigned to a constant, or be an attribute value.

#Notes

  • This refactoring automatically suggests the name for the newly created resource string. You can then modify this name in the Resources browser, and the code will be updated automatically.

#Example

AddLogMessage("Default message:" + "Nice to meet you");
Responder.DefaultMessage = "Nice to meet you";
AddLogMessage("Default message:" + "Nice to meet you")
Responder.DefaultMessage = "Nice to meet you"

Result:

AddLogMessage("Default message:" + Properties.Resources.NiceToMeetYou);
Responder.DefaultMessage = Properties.Resources.NiceToMeetYou;
AddLogMessage("Default message:" + Properties.Resources.NiceToMeetYou)
Responder.DefaultMessage = Properties.Resources.NiceToMeetYou

#Screenshot

CSharpExtractStringToResourceReplaceAll