Suppose my text file
info.txt contains below data :
ID 1 Name Mary Mark 89
ID 2 Name Mai Mark 67
and my text file
Mobile.txt contains below data :
ID Mobile
1 0993209320
2 0943043094
Here I would suggest to create one
student class with two properties
Mobile and
Message. And add all the mappings into list object of that class as mentioned below :
var infos = System.IO.File.ReadLines("C:\\CodeBlack\\Info.txt");
var mobiles = System.IO.File.ReadLines("C:\\CodeBlack\\Mobile.txt");
var studentInfo = new List<Student>();
studentInfo.Add(new Student
{
Mobile = "Mobile",
Message = "Message"
});
foreach (var info in infos)
{
var id = info.Split(' ')[1].ToString();
var mobile = string.Empty;
mobile = mobiles.Where(m => m.Split(' ')[0] == id).Select(m => m.Split(' ')[1]).FirstOrDefault();
studentInfo.Add(new Student
{
Mobile = mobile,
Message = info
});
}
Student Class :
public class Student
{
public string Mobile { get; set; }
public string Message { get; set; }
}
Now you can use studentInfo to export it to excel.
Code for export to excel is easily available on net.
Regards,
CodeBlack