Click here to Skip to main content
15,898,020 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I need to write my own implementation of a function which asks the user what they need to replace a fixed words in an existing document (.doc that contains only text) to.

example: box appears to the user, "Replace user name to?" then the user enters Mike, then the program searches for all instances of "user name" in the existing document and replaces them all with Mike.

Much appreciated!

1- Program asks "Replace user name to?" then the user enters Mike or any input.
2- Programs opens an existing .doc document (which will be treated a s a template, each time the program is used it will use it)
3- Program replaces user name with Mike throughout the document.
4- Program saves a copy of the new document on the desktop and informs the user that it is saved.

What I have tried:

I cannot seem to reference the existing document correctly or use the function correctly, it's been a few years since I last used C# and I can use a refresh.
Posted
Updated 23-Aug-16 4:46am
v3
Comments
Patrice T 23-Aug-16 10:52am    
And you already started to work ?

1 solution

We can't really answer this as we have no idea what your "document" consists of: it could be anything from a zip file containing XML (.epub) to a straight text file.

But... the String class has a Replace method which will do it for "basic" strings.
C#
string replaced = inputString.Replace("user name", "Mike");

If that isn't what you need, you need to supply a whole load more info before we can help!
 
Share this answer
 
Comments
Member 12699376 23-Aug-16 10:47am    
Added more info, thanks for trying to help :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900