0

We have the following code:

If Not File.Exists(trancheDataPath & sDealName & ".txt") OrElse (trancheInsert <> File.ReadAllText(trancheDataPath & sDealName & ".txt")) Then
            File.WriteAllText(trancheDataPath & sDealName & ".txt", trancheInsert)
        End If

We have a string of data that we want to compare with the content in the file and see if there is any change/difference in the new data. Currently, I am using the following method to do this:

trancheInsert <> File.ReadAllText("E:\Stored.txt")

where trancheInsert is of string type and contains the new data.

Similar to above code mentioned, there are similar pieces of code to write to 15 files in a function being called parallely, which occupies a lot of memory.

So,is there a better,faster and memory-efficient way than the above method being used to compare the data?

vikky
  • 171
  • 1
  • 1
  • 16
  • 1
    You should calculate a hash of each of the two text values - probably MD5 - and then compare the two results. That's how many download sites enable you to validate a file after downloading it. There is plenty of information around on the subject of calculating hashes. – jmcilhinney Nov 12 '20 at 11:11
  • A checksum will [probably be slower](https://stackoverflow.com/questions/1358510/how-to-compare-2-files-fast-using-net) than a byte by byte comparison – Alex B. Nov 12 '20 at 11:15
  • https://stackoverflow.com/a/28834817/14171304 – dr.null Nov 12 '20 at 13:19

0 Answers0