.NET Tutorial

Externalizing an Embedded String

In this lesson, you will use Globalyzer to locate and externalize the embedded strings that the scanner found in a sample source file.

  1. Display the the issue-sorted view of embedded strings in the Scan Results table and double-click the string Count Zero. The issue is highlighted in the simpleSuccess.aspx source file, as shown below.

  2. Without deselecting the highlighted text, click the Externalize selected String button in the Toolbar, or right click on the issue and then select Externalize String. Note that the string "<b>Count Zero</b>" has been replaced by:

    <%=GetString("SIMP_COUNTZE_1")%>

    Here's how your source code should now look:

  3. Once externalized, the entry will be removed from the Scan Results table.

  4. Globalyzer will automatically save your source file during string externalization. To save other file changes, select File=>Save in the Menu Bar, click the Save button, or use the shortcut Ctrl-S.

  5. Using the Project Explorer, navigate to the directory where you put the resource file.

  6. You should see a file named MyResources.resx. Right click on it then select Open with=>Text Editor. The following line should appear at the bottom of the file:

    <data name="SIMP_COUNTZE_1" xml:space="preserve"><value>[CDATA[<>Count Zero</b>]]</value></data>

    Note: Any tags present will have been reformatted as needed to work with the resx format. This is the reason you see the html code for < and > rather than the actual characters themselves.

    The name/value pair for the externalized string has been written to the resource file. The key, SIMP_COUNTZE_1, populates the name attribute of the XML data element and was automatically generated by Globalyzer. It is the key that will be used by the GetString method to retrieve the display text, Count Zero.

In the next lesson, you will use the Scan Results table to externalize multiple strings at once using the Externalize Selected Strings feature.