Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to compare the text in two files using c#?

How to compare the text in two files using c#?

Scheduled Pinned Locked Moved C#
questioncsharptutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    svt gdwl
    wrote on last edited by
    #1

    Consider that there are two files named file1.txt and file2.txt. file1.txt consists 50lines file2.txt consists 50lines Now I want to compare the text of two files taht to line by line, I mean How can I compare 1st line of file1.txt with 1st line of file2.txt similarly 2nd line of file1.txt with 2nd line of file2.txt, etc., till the last line

    L V 2 Replies Last reply
    0
    • S svt gdwl

      Consider that there are two files named file1.txt and file2.txt. file1.txt consists 50lines file2.txt consists 50lines Now I want to compare the text of two files taht to line by line, I mean How can I compare 1st line of file1.txt with 1st line of file2.txt similarly 2nd line of file1.txt with 2nd line of file2.txt, etc., till the last line

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      string[] file1 = File.ReadAllLines("file1.txt"); string[] file2 = File.ReadAllLines("file2.txt"); then use "for" to go through the array and compare it.

      1 Reply Last reply
      0
      • S svt gdwl

        Consider that there are two files named file1.txt and file2.txt. file1.txt consists 50lines file2.txt consists 50lines Now I want to compare the text of two files taht to line by line, I mean How can I compare 1st line of file1.txt with 1st line of file2.txt similarly 2nd line of file1.txt with 2nd line of file2.txt, etc., till the last line

        V Offline
        V Offline
        vinodkrebc
        wrote on last edited by
        #3

        You have to use StreamReader Suppose you have Two streamreader objects sr1 and sr2 while((str1=sr1.ReadLine())!="" &&(str2=sr2.ReadLine())) { if(str1!=str2) //The Files Are different... }

        Vinod Kumar Prajapati Software Engineer EBC Publishing Pvt. Ltd.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups