Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two text files and the content of the file1 is :-
400^20140211^0^H^010000^A
400^20140211^0^H^020000^A
400^20140211^0^H^030000^A
400^20140211^0^H^040000^A
400^20140211^0^H^050000^A

content of the file 2 is :-

400^20140211^0^H^010000^A
400^20140211^0^H^020000^C
400^20140211^0^H^030000^B
400^20140211^0^H^040000^A
402^20140211^0^H^050000^A

I need to compare the first columns of the text files and retrieve the data which is present in the second file and not present in the 1st file. Rest of the columns I do not want to do anything . Only the first column . For example here 402 is present in file2 . So the output will be 402. Like that. Please help
Posted
Comments
ZurdoDev 12-Feb-14 13:36pm    
Where are you stuck?
DEbopm 12-Feb-14 13:46pm    
how to get the first 3 digits of a text file that is 400. I need to take the 400 in a text file or 402 in another text file
ZurdoDev 12-Feb-14 13:58pm    
Use can use the File class to read in text files. http://msdn.microsoft.com/en-us/library/system.io.file(v=vs.110).aspx

1 solution

This is the working parts of the code, I'll leave it up to you to to test for valid files, for valid content and End of File (EOF) for one or the other file.

C#
StreamReader readFile_1 = new StreamReader(pathToFile_1);
StreamReader readFile_2 = new StreamReader(pathToFile_2);
//Get line from file and split into arrays
string inputString = readFile_1.ReadLine();     // File 1
string[] dataFile_1 = inputString.Split('^');

inputString = readFile_2.ReadLine();
string[] dataFile_2 = inputString.Split('^'); // File 2

// Extract the values
string valueFile_1 = dataFile_1[0];
string valueFile_2 = dataFile_2[0]; ;

// Test your values use whatever conditional
// values you wish such as the 402 value
if (valueFile_1 == valueFile_2)
{
    // Do whatever you do when they match
}
else
{
    // Do whatever you do when they don't match
}

Good luck.
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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