|
-
Feb 9th, 2011, 12:14 PM
#1
Thread Starter
Lively Member
[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
-
Feb 9th, 2011, 12:28 PM
#2
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 -
-
Feb 9th, 2011, 12:58 PM
#3
Thread Starter
Lively Member
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
-
Feb 9th, 2011, 01:34 PM
#4
Fanatic Member
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
Last edited by J-Deezy; Feb 9th, 2011 at 01:42 PM.
If I helped you out, please take the time to rate me 
-
Feb 9th, 2011, 02:06 PM
#5
Thread Starter
Lively Member
Re: [RESOLVED] How to count the lines of a text file (NOT EVERY LINE) situated on a s
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|