Development Environment    

Finding and Replacing a String

You can search for a specified string within multiple files, and replace the string within a file.

Finding a String.   To search for a string in files:

  1. Click the find button in the Editor/Debugger toolbar, or select Find and Replace from the Edit menu.
  1. The Find & Replace dialog box appears. This is similar to the Find dialog box in the Current Directory browser.

  1. Complete the Find & Replace dialog box to find all occurrences of the string you specify.
    1. Type the string in the Find what field.
    2. Select the files or directories to search through from the Look in list box.
    3. Limit the search using Match case, Whole word, or Wrap around. These settings are remembered for your next MATLAB session.
  2. Click Find.
  3. Open any M-files in the results list by doing one of the following:
  1. The M-file opens, scrolled to the line number shown in the results section of the Find & Replace dialog box.

  1. If you perform another search, the results of each search are accessible via tabs just below the results list. Click a tab to see that list of results as well as the search criteria.

Finding the Next or Previous Occurrence of the String.   To find the next occurrence of the string you entered in the Find & Replace dialog box, click the Find button (or press the Enter key) if the dialog box is open (and has focus). If the Find & Replace dialog box is closed, select Find Next from the Edit menu.

To find the previous occurrence of that string (find backwards), select Find Previous from the Edit menu.

Function Alternative.   Use lookfor to search for the specified string in the help in all M-files on the search path.

Replacing a String.   After searching for a string within files, you can replace the specified content in the current file.

  1. Open the file in the Editor if it is not already open. You can open it from the Find & Replace dialog box--see step 4 in Finding a String. Be sure that the file in which you want to replace the string is the current file in the Editor.
  2. Be sure the Look in field in the Find & Replace dialog box shows the name of the file in which you want to replace the string.
  3. In the Replace with field, type the text that is to replace the specified string.
  4. Click Replace to replace the string in the selected line, or click Replace All to replace all instances in the currently open file.
  1. The text is replaced.

  1. To save the changes, select Save from the File menu.

You can repeat this for multiple files.

  Arrow and Control Keys to Navigate in the Editor Incremental Search