How do I locate a particular word in a text file using C#

Posted by cmrhema on Stack Overflow See other posts from Stack Overflow or by cmrhema
Published on 2010-04-08T01:19:21Z Indexed on 2010/04/08 1:23 UTC
Read the original article Hit count: 295

Filed under:
|
|
|

Hi,

I am sending mails (in asp.net ,c#), having a template in text file (.txt) like below

User Name :<User Name>

Address : <Address>.

I used to replace the words within the angle brackets in the text file using the below code

StreamReader sr;
sr = File.OpenText(HttpContext.Current.Server.MapPath(txt));

copy = sr.ReadToEnd();

sr.Close(); //close the reader

copy = copy.Replace(word.ToUpper(),"#" + word.ToUpper()); //remove the word specified UC


//save new copy into existing text file

FileInfo newText = new FileInfo(HttpContext.Current.Server.MapPath(txt));

StreamWriter newCopy = newText.CreateText();
newCopy.WriteLine(copy);
newCopy.Write(newCopy.NewLine);
newCopy.Close();

Now I have a new problem,

the user will be adding new words within an angle, say for eg, they will be adding <Salary>.

In that case i have to read out and find the word <Salary>.

In other words, I have to find all the words, that are located with the angle brackets (<>).

How do I do that.

Kindly do let me know.

Thanks.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET