vb.net怎么从文件指定行开始读到指定行结束

tengye19840704 2008-03-25 03:07:59
vb.net怎么从文件指定行开始读到指定行结束,,例如下面文件从[DB]开始读到[DBCOMMON]结束

[DB]

#DB接続プール設定
JDBC_USE_CONN_POOL=true

JDBC_CONN_POOL_MAX=5

JDBC_CONN_POOL_MIN=2

JDBC_ORACLE_CONN_CACHE_SCHEME=DYNAMIC_SCHEME

[DBCOMMON]
...全文
219 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
herol 2008-03-25
  • 打赏
  • 举报
回复
似乎楼上一着急又看错了,不是死循环,哎,算了,仅供参考吧,有什么问题自己修改一下
herol 2008-03-25
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 herol 的回复:]
VB.NET code
Dim sr As IO.StreamReader = New IO.StreamReader("SQLTemp.txt")
Dim strSQL As String = ""
Dim strRead As String = ""
While sr.EndOfStream = False
strRead = sr.ReadLine
if strRead = [DB] then
While strRead = [DBCOMMON]
strRead = sr.ReadLine
strSQL += strRead
End While
end if
End While




不好意思,没注意有问题,修改一下
[/Quote]

While strRead = [DBCOMMON]
strRead = sr.ReadLine
strSQL += strRead
End While

这是死循环,写的不对,比较忙,还是自己看看换个判断条件就应该好用了
herol 2008-03-25
  • 打赏
  • 举报
回复

Dim sr As IO.StreamReader = New IO.StreamReader("SQLTemp.txt")
Dim strSQL As String = ""
Dim strRead As String = ""
While sr.EndOfStream = False
strRead = sr.ReadLine
if strRead = [DB] then
While strRead = [DBCOMMON]
strRead = sr.ReadLine
strSQL += strRead
End While
end if
End While


不好意思,没注意有问题,修改一下
fairy4 2008-03-25
  • 打赏
  • 举报
回复

'聲明INI配置檔讀寫API函數
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Int32, ByVal lpFileName As String) As Int32
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Int32
'定義讀取配置檔函數
Public Function GetINI(ByVal Section As String, ByVal AppName As String, ByVal lpDefault As String, ByVal FileName As String) As String
Dim Str As String = LSet(Str, 256)
GetPrivateProfileString(Section, AppName, lpDefault, Str, Len(Str), FileName)
Return Microsoft.VisualBasic.Left(Str, InStr(Str, Chr(0)) - 1)
End Function
'定義寫入配置檔函數
Public Function WriteINI(ByVal Section As String, ByVal AppName As String, ByVal lpDefault As String, ByVal FileName As String) As Long
WriteINI = WritePrivateProfileString(Section, AppName, lpDefault, FileName)
End Function
讀取

Try
Dim path As String
path = Application.StartupPath + "\reportTool.ini "
Me.txtTrioLabel.Text = GetINI("DB", "JDBC_USE_CONN_POOL", "", path)
Me.txtCFlag.Text = GetINI("DB", "JDBC_CONN_POOL_MAX", "", path)
....
Catch ex As Exception
' MsgBox(ex.Message)
End Try


注意:配置文件格式
【字段】

JDBC_USE_CONN_POOL=數值或字串
....

tengye19840704 2008-03-25
  • 打赏
  • 举报
回复
读出来都是空值,,高人..
herol 2008-03-25
  • 打赏
  • 举报
回复

Dim sr As IO.StreamReader = New IO.StreamReader("SQLTemp.txt")
Dim strSQL As String = ""
While sr.EndOfStream = False
if sr.ReadLine = [DB] then
strSQL += sr.ReadLine
elseif sr.ReadLine = [DBCOMMON] then
Exit while
end if
End While

16,717

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧