Is there a way to replace the nth (given occurrence) of a text in MS Word document using C#’s
Application.Selection.Find.Execute Method?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, that method alone cannot accomplish your goal as it only allows all, none, or first replacement. But the API suite is total is more than powerful enough to do what you want to do, you just have to fiddle with it until you find the right API calls to get what you want.
Here are some important documents:
The first link is the overview. In particular, you need to combine the calls in the second two to do what you want: loop using a search, stop and do a replace and the selected text at your desired occurrence. Using a new complex API can be difficult but use the examples and search for API methods for similar code to get ideas.