Replacing Text

You can replace any string of characters contained in the source code of an active editor window.

By default, Replace restarts a search from the beginning when the end of the source code is reached. However, you can change the default setting and instruct Replace to terminate when the end of the source is reached by setting the Stop find at end editor option described in Program Editor Options in the Using Natural Studio documentation.

Start of instruction setTo replace a character string

  1. From the Edit or context menu, choose Replace.

    Or:
    Choose the following toolbar button:

    graphics/pgm_replace.png

    Or:
    Press CTRL+H.

    The Replace dialog box appears.

  2. In the Replace dialog box, you can specify the following:

    • In the Find combo box, enter the character string to be found or select a string from the drop-down list box. All character strings used in previous searches are retained in the list box for the duration of the current Natural session.

    • In the Replace with combo box, enter a replacement string or select a string from the drop-down list box. All character strings used for previous replacements are retained in the list for the duration of the current Natural session.

    • Select the Case sensitive check box (not selected by default) to find and replace only characters strings that exactly match the entry in the Find text box. Otherwise, any combination of upper and lower-case letters will be found and replaced.

    • Select the Whole words only check box (not selected by default) to find and replace whole words only. Otherwise, all occurrences of the string will be found and replaced.

    • Select the Exclude collapsed blocks check box to exclude collapsed blocks from the search and replace functions; do not select the box (this is the default setting) if you want to search and replace in the entire (expanded) source code. Exclude collapsed blocks is only available if structured mode was used for the source(s) to be scanned and if the Expand/Collapse editor option is selected (see Program Editor Options in the Using Natural Studio documentation).

      For more information on expanded and collapsed code blocks, see Showing and Hiding Source Code.

    • Select the Search up check box to perform the search and replace functions from the current position of the text insertion caret to the beginning of the source (up). If this check box is not selected (this is the default setting), the search and replace functions are performed from the current caret position to the end of the source (down).

    • Select the Current editor window radio button (selected by default), if you want to execute the search and replace functions only in the source code contained in the current window of the program editor.

    • Select the All program editor windows radio button, if you want to execute the search and replace functions in the source code contained in all open windows of the program editor.

    • Select the Selection radio button, if you want to execute the Replace All function for a selected portion of source code. This button is only enabled, if the text selected in the current editor window spans one or more lines. The buttons Find Next and Replace are then disabled.

    • You can choose the Help button to invoke the online documentation for help information on replacing text.

  3. Choose the button Find Next, Replace or Replace All to execute the find and/or replace function.

    Depending on the setting of the Search up check box, the find and/or replace goes down or up the source code from the current caret position. If no instance of the search string is found, a corresponding message is displayed. If an instance of the search string is found, the following applies:

    • If Find Next was selected, the search string is selected.

    • If Replace was selected, the previously selected search string is replaced by the replacement string.

    • If Replace All was selected, all search strings found are replaced by the replacement string.

  4. If the first instance of a search string is selected, you can go to the next instance by choosing one of the following methods:

    From the Edit or context menu, choose Find Next or Replace Next.

    Or:
    Choose one of the following toolbar buttons:

    graphics/edis_find_next.png for Find Next

    graphics/pgm_replace_next.png for Replace Next

    Or:
    Press F3 for Find Next or CTRL+F3 for Replace Next.

  5. You can choose the Close button to close the Replace dialog box. However, you can also edit the current source when the Replace dialog box is open.

    When the Replace dialog box is closed, you can continue the find and/or replace functions by using the alternative methods described earlier in Step 4.