Visual basic 8

2010-03-21 1:42 am
I want to ask how to check how many rows of the text from the textfile. For example, there are 4 rows of the name below:
Linda Kowalski
Andre Ursini
Julia Jenkins
Tom Mosby

What are the code for check how many rows when this 4 rows are stored at the txtfile called name.txt ?

回答 (1)

2010-03-22 10:34 am
✔ 最佳答案
You can use .NET Framework's System.IO.File class or System.IO.StreamReader class to read a text file.

I show you an example on File class

Imports System
Imports System.IO
Imports System.Text

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Open and read the content of a file
Dim data As String = File.ReadAllText("c:\temp\name.txt")
Dim s() As String = {vbLf} ' this is the line feed character
' put the file content in an array separated by line feed
Dim result() As String = data.Split(s, StringSplitOptions.RemoveEmptyEntries)
' find out how many elements in the array
Dim i As Integer = result.Length
MessageBox.Show(i.ToString())
End Sub
End Class

2010-03-22 02:38:10 補充:
Look at this link for an example on using StreamReader class

http://tw.knowledge.yahoo.com/question/question?qid=1510031703520


收錄日期: 2021-04-26 13:12:24
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20100320000051KK01145

檢視 Wayback Machine 備份