Have you or your users ever opened a file in Word only to discover that the document contained a lot of “garbage” or extraneous characters? Chances are, you probably used Word’s find and replace feature to clean it up. You just globally replace the character or phrases with nothing.
But what if the character strings aren’t all the same? You could resort to copying the strings and pasting them into the Find and Replace dialog box. However, by the time you do that, you might as well just delete the strings manually after you’ve selected them.
Fortunately, the Find and Replace dialog box lets you use wildcard characters to locate similar (but non-identical) character strings. That capability can save you and your users lots of editing time. Here’s how that feature saved the day for me recently.
It’s a wild and crazy process
Recently my colleagues at TechProGuild , TechRepublic’s subscription-based service, invited me to host an online chat about tech support. (You can read excerpts from the transcript here .)
The system that generates the transcript of the chat stamps each line with the current date and time, as shown in Figure A. The problem, of course, is how to get rid of those date and time stamps.
|We want to remove all of the date and time stamps from this document without visiting each line manually.|
One of TechProGuild’s editors, Mike Jackman, showed me the trick he uses to clean up these transcripts, and it couldn’t be easier—I had simply never tried it before. To demonstrate how it works, I’ll show you how we got rid of all of the date and time stamps that precede the phrase SPEAKER_jdavis:, and replaced those strings with my initials, JD, a colon, and two spaces.
To begin, I selected the first string, beginning at the left margin and including the colon, and pressed [Ctrl]C to copy that string. Next, I pressed [Ctrl]H to open the Find and Replace dialog box and pasted that string into the Find what field.
Next, I clicked the More button and activated the checkbox for the Use wildcards option, and then typed JD: followed by two spaces in the Replace with field. So far, so good. However, if I clicked the Replace or Replace All button at this point, I’d only get rid of one of the date and time strings—the one stamped 08:59:46 P.M.
Since the time of day is the only portion of that string that changes throughout the document, I positioned my cursor on the time portion, pressed [Insert] to toggle into overstrike mode, and typed question marks (?) over each character in the time string, up through and including the greater-than symbol (>), as shown in Figure B. When I clicked the Replace All button, Word replaced all of the strings that began with Tue Dec 14 and ended with speaker_jdavis:—regardless of the time stamp—and all of the my comments in the transcript were immediately “cleaned up” and replaced, with the result as shown in Figure C.
|To use wildcards in a Find what field, you must activate the Use wildcards option.|
|This is what my document looked like after I clicked Replace All.|
At this point, to finish cleaning up the document, I simply repeated that process for each of the people who posted comments during the chat. It took a little while to do the copying, pasting, and replacing, but it took a lot less time than if I had manually edited the document.
Some of you are probably wondering why I typed over the greater-than symbol (>) with the question mark, since only the time stamp changed from line to line. The answer is that the greater-than symbol is itself a special character, and if you don’t change it to a question mark, the replace function will fail.
Only the beginning
This lesson is a good start, but there’s more to using wildcards in the Find and Replace dialog box than entering question marks. Like in DOS filename wildcards, question marks stand for a single character, but you can use the asterisk (*) to represent a variable number of characters. However, the Find and Replace dialog box is extremely picky about how you use wildcards in combination with one another.
We’ll take a closer look at some of the other uses for this feature in a future article. Meanwhile, if you’d like to share your favorite wildcard tip, please post a comment below or send me a note.