//--- Required for IEnumerator
using System.Collections;
...
WordApplication app = new WordApplication();
Document doc = app.Open(@"c:\myDoc.doc");
//--- Search a document for social security numbers, or any series of
//--- nine digits, and remove them. The question mark after each dash
//--- makes the presence of the dash optional.
IEnumerator searcherator = doc.Search(@"\d\d\d-?\d\d-?\d\d\d\d").GetEnumerator();
while (searcherator.MoveNext())
{
SearchMatch match = (SearchMatch)searcherator.Current;
match.Element.DeleteElement();
}
|