The Find and Replace functions in the Script Editor allow you to find and replace strings in the Code View text editor. Clicking the Find button or the Replace button on the Code View toolbar menu opens the Find/Replace dialog box, as shown in the figure below. Enter a string to search for in the Find What field.
The replace operation works in a similar way and replaces the Find What string(s) with the Replace With string(s). All dialog options are the same, except that the Replace dialog box has a field called Replace With.
Find/Replace Dialog Box
You can check one or more of the following search options:
Match whole word only: Restricts the search operation to whole-word matches.
Match case: Restricts the search operation to case-sensitive matches.
Direction: Searches up or down within the work area.
When you are ready to execute a find or replace operation, click one of the following buttons:
Find Next: Finds the next match.
Replace: Replaces a single match and then advances to the next match.
Replace All: Replaces all occurrences of the search text with the replacement text.
The Script Editor supports wildcards in the search string, but not the replace string. Wildcards support the Visual Basic "like" operator syntax. This includes the familiar DOS wildcards "*" and "?", plus some others. The like function is used to perform string comparison; it searches for a pattern inside a string and returns a value that indicates whether the pattern is contained in the string or not. The “like” operator accepts three parameters:
You can use these special symbols in pattern matches to match a single character in the source string:
? Accepts any single character.
# Accept a single character if it is digit (0-9).
[charlist] Accepts a single character if it is part of the characters list.
[!charlist] Accept a single character if it is not part of the characters list.
|
Note: To match the special characters left bracket ([), question mark (?), number sign (#), and asterisk (*), enclose them in brackets. The right bracket (]) cannot be used within a group to match itself, but it can be used outside a group as an individual character. |
By using a hyphen (-) to separate the upper and lower bounds of the range, charlist can specify a range of characters. For example, [A-Z] results in a match if the corresponding character position in string contains any uppercase letters in the range A-Z. Multiple ranges are included within the brackets without delimiters.
Other important rules for pattern matching include the following:
An exclamation point (!) at the beginning of charlist means that a match is made if any character except the characters in charlist is found in string. When used outside brackets, the exclamation point matches itself.
A hyphen (-) can appear either at the beginning (after an exclamation point if one is used) or at the end of charlist to match itself. In any other location, the hyphen is used to identify a range of characters.
When a range of characters is specified, they must appear in ascending sort order (from lowest to highest). [A-Z] is a valid pattern, but [Z-A] is not.
The character sequence [] is considered a zero-length string ("").
You can also use the * (asterisk) to match zero or more characters in the string.
It is important to note that the “like” function performs a character-by-character comparison of the source and the compare strings. If these strings have different length, then the comparison will not be possible and the function will return FALSE. The only exception to the aforementioned rule is through the use of the * (asterisk), which can take the place of zero or more characters.