Results 1 to 5 of 5

Thread: [RESOLVED] Read/compare particular line from textfile

  1. #1

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Resolved [RESOLVED] Read/compare particular line from textfile

    Hi,

    I have a 2 textfiles with a few lines of text.

    e.g. textfile1

    pos1:1
    pos2:10
    pos3:1
    pos4:0

    e.g. textfile2

    pos1:1
    pos2:9
    pos3:1
    pos4:0

    I need to open both files and compare the lines without knowing which line is different. (mgsbox (pos2.value)<< something like this)

    Anyone?


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  2. #2
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Read/compare particular line from textfile

    Just open the first one, put in array, open the second and go through each line and compare each line with the same position in the array...

    Sample..

    VB.NET Code:
    1. Dim arrFirst() As String = IO.File.ReadAllLines("PATH")
    2.         Dim reader As New IO.StreamReader("PATH")
    3.         Dim i As Integer = 0
    4.  
    5.         While True
    6.             Dim line As String = reader.ReadLine
    7.             If line Is Nothing Then Exit Sub
    8.             If arrFirst(i) <> line Then
    9.                 MsgBox("Not equal")
    10.                 Exit While
    11.             End If
    12.             MsgBox("Equal")
    13.             i += 1
    14.         End While
    Last edited by mickey_pt; Aug 18th, 2009 at 06:08 AM. Reason: Code

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  3. #3

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Read/compare particular line from textfile

    Thanks mickey, but it seems that I have to correct my question. I do need to know which line is different. Sorry for the misunderstanding.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  4. #4
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Read/compare particular line from textfile

    Instead of the MsgBox that says not equal you can save the line value to a string, or if are several different lines you can add them to an arraylist...

    [EDIT] - The number of the line or the value?

    If it's the number it will be the value of i+1.
    If it's the line string it will be the line string
    Last edited by mickey_pt; Aug 18th, 2009 at 08:23 AM. Reason: Question

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  5. #5

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Read/compare particular line from textfile

    Thanks Mick


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width