Tuesday 15 April 2014

c# - Best method to compare multiple files fields -


I need to create a program (preferably C #) which reads in 2 different types of files (most More likely .txt and .xls) with a slightly different fields and compare each line. For example: File 1 (.txt): Last Name: Smith First Name: Bill EID: BS 223 Type: Accounting File2 (.xls): Last: Smith First: Bill EID: BS 223 Number: 5555555 Type: Accounting < / P>

The file contains some similar fields, some are different. Also, in the text file there will be many places in the middle of the field. I need to compare the common field and display the similarities and differences to the user. The format of the field will be consistent in each file.

My question is, what would be the best option to do this? Would it be wise to convert both files into XML and compare them through? How would XML come in the equation if I used it? Are there better ways in C #

EDIT: Code to convert .txt to XML

  public static zero main () {XElement root = new XElement ("root"); Forash (string LN in file.readlines (@ "input tip")) {string [] field = ln.Split (''); Excellence Record = New Exclamation ("Record"); Int pos = 0; Fresh (string spam in field) {if (sp! = "") {Pos + = 1; Excellence field = new excelment (string format ("field_ {0}", pause .tostring ())); Field.Add (SP); Record.Add (area); }} Root.Add (record); } Console. Write (root. To string ()); }    

How often do you need this exercise? If this is a one-time activity, then I would say that you can read both files in that format in which they are and only make a string comparison. When comparing, be sure to ignore empty space, comma and cover.

Take a look at this, if you are more curious on XML, - but this works internally and I suspect you will improve any performance. And you also have to try to convert them both into XML.

No comments:

Post a Comment