请问怎样可以判断一个TXT文件中有多少行文字?
请问怎样可以判断一个TXT文件中有多少行文字?
[解决办法]
改下
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();
}
[解决办法]
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( "一共有{0:d}行。 ", res.Count + 1)
MessageBox.Show(strRes)
End If