Results 1 to 5 of 5

Thread: [RESOLVED] How to count the lines of a text file (NOT EVERY LINE) situated on a server

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2008
    Posts
    75

    Resolved [RESOLVED] How to count the lines of a text file (NOT EVERY LINE) situated on a server

    Hi,

    I have a text file on a web server. Every line of the text file ends with "g]" or with "a]".

    I would like to count the lines that end with "g]" and the lines that end with "a]".

    How can I do that?
    Before I hade two seperate files and I used the following code for counting.
    But now I decided to put everthing into a single file:

    Code:
    Dim client1 As New System.Net.WebClient
            Dim file1 As String = client.DownloadString("URL/file1") 'lines ending with "g]"
            Dim lines1 As String() = file1.Split(Environment.NewLine)
            Dim client2 As New System.Net.WebClient
            Dim file2 As String = client2.DownloadString("URL/file2") 'lines ending with "a]"
            Dim lines2 As String() = file2.Split(Environment.NewLine)
            MsgBox("There are " & lines1.Length & " red cars" & vbNewLine & "There are " & lines2.Length & " black cars")

    Thank you in advance,

    Andrea

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: How to count the lines of a text file (NOT EVERY LINE) situated on a server

    Well, you have the lines store in a string array (as shown in your code). You just have to loop through that array and start counting
    Code:
    Dim aCount, gCount as integer
    For Each line as string in lines1
       if line.EndsWith("a]") Then
          aCount += 1
       elseif line.EndsWith("g]") Then
          gCount += 1
      End If
    Next
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2008
    Posts
    75

    Re: How to count the lines of a text file (NOT EVERY LINE) situated on a server

    Well thanks a lot stanav!
    I was confused! but thanks to you I amde it!
    Yayyy

  4. #4
    Fanatic Member
    Join Date
    Aug 2010
    Posts
    624

    Re: [RESOLVED] How to count the lines of a text file (NOT EVERY LINE) situated on a s

    Or, another option:

    vb.net Code:
    1. Using wClient As New Net.WebClient
    2.      Dim FileLines As String() = wClient.DownloadString("URL/File1").Split(ChrW(10))
    3.      Dim countA As Integer = (From singleLine In FileLines Where singleLine.EndsWith("a]") Select singleLine).Count
    4.      Dim countG As Integer = FileLines.Count - CountA
    5. End Using
    Last edited by J-Deezy; Feb 9th, 2011 at 01:42 PM.
    If I helped you out, please take the time to rate me

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2008
    Posts
    75

    Re: [RESOLVED] How to count the lines of a text file (NOT EVERY LINE) situated on a s

    Great,
    Thank you J-Deezy

Tags for this Thread

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