- 分享
- 0
- 人气
- 0
- 主题
- 7
- 帖子
- 4707
- UID
- 82675
- 积分
- 5108
- 阅读权限
- 22
- 注册时间
- 2007-6-18
- 最后登录
- 2021-7-27
- 在线时间
- 5767 小时
  
|
原帖由 goodhermit95 于 2008-11-1 11:37 PM 发表 
streamreader.readtoend
streamreader.readline ,怎么只Read一个Line?但是不能【streamreader.readline(制定行数)】
[Copy to clipboard] [ - ]CODE:
Imports System
Imports System.IO
Public Class ReadALine
Private Sub ReadOneLine()
Dim sr As New Streamreader("C:\Test.Txt")
Dim textdata As String
textdata = sr.ReadToEnd
Dim line As String() = textdata.Split(vbCrLf)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
For i As Integer = 0 To line.Count - 1
If i = 5 Then'5 = 要读的行数
textdata = line(i)
End If
Next
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
For i As Iteger = 0 To line.Count - 1
If line(i).ToString.Contains("Text") Then
textdata = line(i)
End If
Next
End Sub
End Class
看不懂在这里问~~
1. 因為你的 for 是從 0 開始, 那麼 i = 5 應該是第六行才對吧?
2. 如果只是要列出指定行數, 另一個 for 即是多餘的了. 那個 for 是要搜索行數中只包含 "Text" 字眼 |
|