| |

VerySource

 Forgot password?
 Register
Search
View: 1458|Reply: 16

How can I tell how many lines of text are in a TXT file?

[Copy link]

5

Threads

16

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 Invalid IP Address

Post time: 2020-1-15 14:00:01
| Show all posts |Read mode
How can I tell how many lines of text are in a TXT file?
Reply

Use magic Report

0

Threads

60

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-1-18 17:54:01
| Show all posts
Read line by line with READLINE (),
Add a counter variable to the while loop,
Reply

Use magic Report

5

Threads

16

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

 Author| Post time: 2020-1-18 18:54:02
| Show all posts
How to write, please help
Reply

Use magic Report

0

Threads

60

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-1-18 21:45:01
| Show all posts
C # or else
I write
Reply

Use magic Report

0

Threads

60

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-1-19 09:45:02
| Show all posts
private int countline (string fullfilename)
{
System.IO.StreamReader sr = new System.IO.StreamReader (fullfilename);
int line = 0;
while (sr.ReadLine ()! = null)
{
line ++;
}
return line;


}

Main function call


private void Page_Load (object sender, System.EventArgs e)
{
// Place user code here to initialize the page
int cc = countline (@ "c:\1.txt");
Response.Write (cc);
}
Reply

Use magic Report

5

Threads

16

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

 Author| Post time: 2020-1-19 16:00:01
| Show all posts
Is there any VB.NET?
Reply

Use magic Report

0

Threads

60

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-1-19 17:18:01
| Show all posts
Turn it down easily, search for a transcoding website online
Reply

Use magic Report

0

Threads

60

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-1-19 20:36:02
| Show all posts
Change
private int countline (string fullfilename)
{
System.IO.StreamReader sr = new System.IO.StreamReader (fullfilename);
int line = 0;
while (sr.ReadLine ()! = null)
{
line ++;
}
return line;
sr.Close ();


}
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-22 00:09:01
| Show all posts
Dim dlg As New OpenFileDialog
        dlg.InitialDirectory = "c:\"
        dlg.Multiselect = False
        dlg.CheckFileExists = True
        If dlg.ShowDialog () = Windows.Forms.DialogResult.OK Then
            Dim fs As IO.FileStream = dlg.OpenFile ()
            Dim bzData As Byte ()
            ReDim bzData (fs.Length)
            fs.Read (bzData, 0, fs.Length-1)
            Dim strFileData As String = System.Text.Encoding.ASCII.GetString (bzData)
            Dim res As System.Text.RegularExpressions.MatchCollection
            res = System.Text.RegularExpressions.Regex.Matches (strFileData, "\r\n")
            Dim strRes As String = String.Format ("There are {0: d} lines in total.", Res.Count + 1)
            MessageBox.Show (strRes)
        End If
Reply

Use magic Report

0

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-23 15:27:02
| Show all posts
You can read it all at once, and then count the number of carriage return and line feed symbols in it
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list