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:
- Click the find button in the Editor/Debugger toolbar, or select Find and Replace from the Edit menu.
- The Find & Replace dialog box appears. This is similar to the Find dialog box in the Current Directory browser.
- Complete the Find & Replace dialog box to find all occurrences of the string you specify.
- Type the string in the Find what field.
- Select the files or directories to search through from the Look in list box.
- Limit the search using Match case, Whole word, or Wrap around.
These settings are remembered for your next MATLAB session.
- Click Find.
Open any M-files in the results list by doing one of the following:
- If you set Look in to
Current File, the next occurrence of the string is highlighted in the file.
- If you set Look in to search through multiple files, results appear in the lower part of the Find & Replace dialog box and include the filename, M-file line number, and content of that line.
- Double-clicking a file
- Selecting files and pressing the Enter or Return key
- Right-clicking selected files and selecting Open from the context menu
- The M-file opens, scrolled to the line number shown in the results section of the Find & Replace dialog box.
- 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.
- 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.
- 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.
- In the Replace with field, type the text that is to replace the specified string.
- Click Replace to replace the string in the selected line, or click Replace All to replace all instances in the currently open file.
- The text is replaced.
- 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 |