Comparing lines
-
I'm working on a program that compares lines from two .txt files line by line. It compares the first line of the first file then first line of the second file and so on. But when the two files have different number of lines the program will fall. How to solve this problem.
C#
-
I'm working on a program that compares lines from two .txt files line by line. It compares the first line of the first file then first line of the second file and so on. But when the two files have different number of lines the program will fall. How to solve this problem.
C#
You can simply do it by checking the line you get first from the stream before comparing it with what so ever, sorry but not sure how to do it in c#, however you have to look for the "end of file" escape character, we use EOF in c++..
while(youStreamReader.ReadLine() != EOF)
dadadadada...Another alternative is that you can read the entire file contents once before starting the comparison process and determine the number of lines "using the end of line escape character which you have to find out:)" and use this number in your loop to break it later.. hope this was of some help.
Smile: A curve that can set a lot of things straight! (\ /) (O.o) (><)
-
I'm working on a program that compares lines from two .txt files line by line. It compares the first line of the first file then first line of the second file and so on. But when the two files have different number of lines the program will fall. How to solve this problem.
C#
When two lines do not match, you need to search ahead in both files, to see if either file has a line ahead that matches ( or better matches ) the current one. A brute force approach here is going to be very expensive, I would think.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )