简体   繁体   中英

reading email id from a file and replacing it

I am using visual studio 2010 and I have,

qiongshuailv@163.com i

e_sqwang@zzu.edu.cn

these are two email id which is given in a xml file what I want to do is that I want to find the ids and replace it with

< email >qiongshuailv@163.com< /email >

< email >ie_sqwang@zzu.edu.cn< /email >

Now the problem is that the email id may change in different files so is it possible to replace the id with the above statement for every other email id.

Please anyone that can help me with the logic, it will be appreciated.

This should do the trick.

string path = "Sample.txt";
File.WriteAllLines(path, File.ReadLines(path).Select(x => string.Format("<email>{0}</email>", x)).ToArray());

These are the steps, regardless of C# or VB.NET:

  • . Read the file, line by line into a List<string> list
  • . Close the file, reopen the file for writing
  • . foreach(var s in list){ file.Write("<email>"+s+"</email>");}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM