[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
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
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
Re: [RESOLVED] How to count the lines of a text file (NOT EVERY LINE) situated on a s
Or, another option:
vb.net Code:
Using wClient As New Net.WebClient
Dim FileLines As String() = wClient.DownloadString("URL/File1").Split(ChrW(10))
Dim countA As Integer = (From singleLine In FileLines Where singleLine.EndsWith("a]") Select singleLine).Count
Dim countG As Integer = FileLines.Count - CountA
End Using
Re: [RESOLVED] How to count the lines of a text file (NOT EVERY LINE) situated on a s