Click here to Skip to main content
14,732,982 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I currently have two text files which come from two different systems but they have a common itemcode.

I would like to know how could i read the two text files and match the codes to write data from the two files to another text file that gets sent to a third party system?

For example file 1 contains the price(500) of item code 001 while file 2 contains the description(Screen) of itemcode 001

the file3(which is the file i need to create) will have the following in it

1 solution

There are a huge number of ways to do this: but assuming that the two files are not necessarily in the same order, I would create a class which contained the Price and Description (call it "Item" maybe) then create a Dictionary of Items:
private Dictionary<int, Item> items = new Dictionary<int, Item>();

I would then read each file in turn, breaking it into itemcode and either Price or Description and do this with each row:
if (!items.ContainsKey(itemcode))
   items.Add(itemcode, new Item());
//items[itemCode].Price = price;
//items[itemCode].Description = description;
uncommenting the appropriate line.
At the end, you have a Dictionary which contains each Item, hopefully complete with each Price and Description.

It's a poor way to store your data though!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900