大虾帮忙看看这段代码~

wanbolantian 2008-05-04 03:34:53
'函数名: sdGetIniInfo
'功能:读取INI文件设置信息
'参数说明:iniFile-->INI文件 iniSection--INI文件中设置的部分名称
'作者:SD
'日期:2005-10-11
'Email:ztqas@126.com
'备注:转载或修改请保留此信息
Function sdGetIniInfo(ByVal iniFile As String, ByVal iniSection As String) As String
If Not File.Exists(iniFile) Then
Return "文件 " & iniFile & " 未找到,请确认路径和文件名是否正确!"
Exit Function
End If

Dim iniRead As New StreamReader(iniFile)
Dim iniStr As String = iniRead.ReadToEnd

Dim i As Integer
Dim cLine As Integer
Dim noSec As Boolean = False
Dim getValue As String = ""
Dim cLst

cLst = iniStr.Split(Chr(13))
cLine = UBound(cLst)

For i = 0 To cLine
If cLst(i).indexof("=") > 0 Then
If cLst(i).split("=")(0).trim() = iniSection Then
noSec = True
getValue = cLst(i).split("=")(1).trim()
Exit For
End If
End If
Next

If noSec = True Then
Return getValue
Else
Return "没有找到 " & iniSection & " 的设置信息!"
End If
End Function

这是在网上搜到的一段在Vb.net中读INI文件的代码,对红色代码部分不是很理解,
为什么在Split之后还能跟参数(0)呢,MSDN中关于Split的用法部分并没有提到这
么用的??那位大虾能解释一下红色代码是什么意思呢?先谢了
...全文
54 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
llsus 2008-05-05
  • 打赏
  • 举报
回复
当然不是,就是普通的数组表示方法
数组"A",你可以通过A(0) 来访问数组元素你是可以理解的,如果有个数组叫做"A(0)"呢?访问他的元素的方法当然是是A(0)(0),这不是很好理解吗?
而这个表示数组的"A(0)"可能是某个集合的元素,也可能是一个函数。
wanbolantian 2008-05-05
  • 打赏
  • 举报
回复
谢谢llsus,解释得非常详细,谢谢……
wanbolantian 2008-05-04
  • 打赏
  • 举报
回复
这种情况属于运算符重载么?
llsus 2008-05-04
  • 打赏
  • 举报
回复
一楼的回复是正确的,split方法返回一个数组,数组当然可以写下标了

我就经常这么用,方便

S = SS(j).Replace("""", ",")
If S.Length < 10 Then Continue For
If S.Substring(0, 5) = "+CMGL" Then
SerialPort1.Write("At+Cmgd=" & S.Split(",")(0).Split(":")(1) & Chr(&HD) & Chr(&HA)) For K As Integer = 1 To 100
System.Threading.Thread.Sleep(10)
If SerialPort1.BytesToRead > 8 Then
System.Threading.Thread.Sleep(200)
S = SerialPort1.ReadExisting
Exit For
End If
Next
ElseIf S.Substring(0, 3) = "((+" Then
RecNo += 1
ReDim Preserve SS1(RecNo)
SS1(RecNo) = S
S = SS(j - 2).Replace("""", ",")
S = S.Split(",")(9)
SS1(RecNo) = SS1(RecNo) & "+" & Format(CDate(S), "yyyy-MM-dd")
End If
llsus 2008-05-04
  • 打赏
  • 举报
回复
那段代码读取Inf文件是有问题的
当多个Section 有相同的字段总是读取先出现的Section 中的字段,永远读不到后面的。关键的问题是它忽略了Inf文件中的Section ,只操作字段
例如INF文件内容如下:
[Server]
IP='192.168.0.1'
Name='MyPC'
[User]
Name='Operater'
PassWord=''
如果想读取用户名称是无法实现的
lcd197508 2008-05-04
  • 打赏
  • 举报
回复
我认为cLst(i).split("=")返回一个数组,在之后的参数是对数组元素的引用也许可以改成
dim section() as strin
section= cLst(i).split("=")
if section(0).trim()=iniSection Then
noSec = True
getValue = cLst(i).split("=")(1).trim()
Exit For
End If

16,555

社区成员

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

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