Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search replace text in textbox 1

Status
Not open for further replies.

jriggs420

Programmer
Sep 30, 2005
116
US
I'm pretty new to C#. Currently I am trying to work with Microsoft's 2005 Visual C# express. Here's what I'm trying to accomplish:
1) Browse to a word doc on my Computer
2) Read .doc into a text box
3) Do some modifications to the contents
4) ftp revised text in .txt format to my server

I am at #3. I have the text from a Word doc into my txtbox, but can't figure out how to do some minor search/replace and text modification. What are my options on how to do this? What terms do I need to search on? Why does M$ help give me more questions than answers? Does anyone have a similar project I could look over. Please let me know if there's any additional info I left out...Thanks for any suggestions, I'm open to any solutions-
Joe

Because a thing seems difficult for you, do not think it impossible for anyone to accomplish.
Marcus Aurelius
 
Ok Joe,

This is actually pretty simple. You've already done the hard part :)


lets say you want to have a replace button that will replace the word "fine" with "ok" in your textbox.

private void btnReplace_Click(object sender, EventArgs e)
{
string doc = txtDocument.Text;

doc.Replace("fine", "ok");
}

All instances of "fine" will be replaced with "ok"


You can also do IndexOf or IndexOfAny to find a word or part of a word in your string.


And finally, if you want to do more complicated searches or replaces, I would recommend you look into a Regex (regular expression).


Hope that gets you started.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top