Quantcast
Viewing all articles
Browse latest Browse all 15

Rex.Split for comma outside of double quotation

</pre>
StringBuilder sb = new StringBuilder();
 var projectlist = new List<Project>();

 var reader = new StreamReader(System.IO.File.OpenRead(@"C:\projectallocations.csv"));
 while (!reader.EndOfStream)
 {
 var line = reader.ReadLine();
 var arry = Regex.Split(line, ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)");
 //var date = DateTime.Parse(arry[0]);
 var projectname = arry[1];
 var user = arry[2].Replace("\"", "");
 var client = arry[3].Replace("\"", "");
 var allocatedhours = Double.Parse(arry[4]);
 var timesheethours = Double.Parse(arry[5]);

var project = new Project()
 {
 DateCreated = DateTime.Now,
 DateModified = DateTime.Now,
 DevLead = user,
 Name = projectname,
 ProjectClient = client,
 AllocatedHours = allocatedhours,
 TimeSheetHours = timesheethours
 };

if (projectlist.Where(x => x.Name.Equals(project.Name)).FirstOrDefault() == null)
 {
 projectlist.Add(project);
 }

 }

foreach (var project in projectlist)
 {
 sb.AppendLine(string.Format("Project Name : {0} \t DevLead : {1} \t AllocatedHours : {2} \r\n {3}", project.Name,
 project.DevLead, project.AllocatedHours, Environment.NewLine));
 }

Response.Write(sb);
<pre>


Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 15

Trending Articles