如何读取指定的一个INI文件?巨急,在线等.请高手指点

clbaddd 2005-09-23 10:44:59
有一个配置文件D:\a.ini,文件格式如下(部分):
[INSTRUCTION]
ANSWER=DT
SR=成功率
QUERY=CX
STATE=状态

[RECVNO]
MOTHER=088572572
BENO=0000
ANSWNO=0001
我如何才能得到指定的某个值呢?例如我现在要得到[INSTRUCTION]中QUERY和[RECVNO]中BENO的值,该怎么做呢?
...全文
140 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
尚和空四 2005-09-23
  • 打赏
  • 举报
回复
研究一下 好用的
尚和空四 2005-09-23
  • 打赏
  • 举报
回复
<%
set IniFileDictionary = CreateObject("Scripting.Dictionary")

Sub IniFileLoad(ByVal FilSpc)
IniFileDictionary.RemoveAll
FilSpc = lcase(FilSpc)
if left(FilSpc, 1) = "p" then
'Physical path
PhyPth = mid(FilSpc, instr(FilSpc, "=") + 1)
else
'Virtual path
PhyPth = Server.MapPath(mid(FilSpc, instr(FilSpc, "=") + 1))
end if

set FilSys = CreateObject("Scripting.FileSystemObject")
set IniFil = FilSys.OpenTextFile(PhyPth, 1)
do while not IniFil.AtEndOfStream
StrBuf = IniFil.ReadLine
if StrBuf <> "" then
'There is data on this line
if left(StrBuf, 1) <> ";" then
'It's not a comment
if left(StrBuf, 1) = "[" then
'It's a section header
HdrBuf = mid(StrBuf, 2, len(StrBuf) - 2)
else
'It's a value
StrPtr = instr(StrBuf, "=")
AltBuf = lcase(HdrBuf & "|" & left(StrBuf, StrPtr - 1))
do while IniFileDictionary.Exists(AltBuf)
AltBuf = AltBuf & "_"
loop
IniFileDictionary.Add AltBuf, mid(StrBuf, StrPtr + 1)
end if
end if
end if
loop
IniFil.Close
set IniFil = nothing
set FilSys = nothing
End Sub

Function IniFileValue(ByVal ValSpc)
dim ifarray
StrPtr = instr(ValSpc, "|")
ValSpc = lcase(ValSpc)
if StrPtr = 0 then
'They want the whole section
StrBuf = ""
StrPtr = len(ValSpc) + 1
ValSpc = ValSpc + "|"
ifarray = IniFileDictionary.Keys
for i = 0 to IniFileDictionary.Count - 1
if left(ifarray(i), StrPtr) = ValSpc then
'This is from the section
if StrBuf <> "" then
StrBuf = StrBuf & "~"
end if
StrBuf = StrBuf & ifarray(i) & "=" & IniFileDictionary(ifarray(i))
end if
next
else
'They want a specific value
StrBuf = IniFileDictionary(ValSpc)
end if
IniFileValue = StrBuf
End Function
%>
尚和空四 2005-09-23
  • 打赏
  • 举报
回复
<html>

<head>
<title>INI文件读取</title>
</head>

<body>

<p>读取物理路径下的ini文件...<%
call IniFileLoad("physical=c:\boot.ini")
%></p>

<p>列出所有的ini信息:<%
dim TempArray
TempArray = IniFileDictionary.Keys
for i = 0 to IniFileDictionary.Count - 1
Response.Write("<br>" & TempArray(i) & "=" & IniFileDictionary(TempArray(i)))
next
%></p>

<p>显示确定值:<%
StrBuf = IniFileValue("boot loader|timeout")
Response.Write("<br>'[boot loader] timeout' value = " & StrBuf)
StrBuf = IniFileValue("boot loader")
Response.Write("<br>'[boot loader]' section = " & StrBuf)
%></p>

<p>列出所有的ini信息:<%
call IniFileLoad("virtual=/readini/test.ini")
%></p>

<p>Dump the dictionary:<%
TempArray = IniFileDictionary.Keys
for i = 0 to IniFileDictionary.Count - 1
Response.Write("<br>" & TempArray(i) & "=" & IniFileDictionary(TempArray(i)))
next
%></p>

<p>显示确定值:<%
StrBuf = IniFileValue("names|name2")
Response.Write("<br>'[names] name2' value = " & StrBuf)
StrBuf = IniFileValue("colors")
Response.Write("<br>'[colors]' section = " & StrBuf)
%></p>
</body>
</html>
clbaddd 2005-09-23
  • 打赏
  • 举报
回复

再顶一下
wanghui0380 2005-09-23
  • 打赏
  • 举报
回复
asp中是不可以用api的

如果能用api,那asp中很多问题就简单了.不过客户的安全就---- 嘿嘿,有api我想干嘛不行
clbaddd 2005-09-23
  • 打赏
  • 举报
回复
晕啊,我也是刚看了那篇文章,听说是不是可以有一个API函数WritePrivateProfileString可以执行,但具体怎么用?是这个函数吗
wanghui0380 2005-09-23
  • 打赏
  • 举报
回复
http://www.knowsky.com/301898.html
dingjin_dj 2005-09-23
  • 打赏
  • 举报
回复
up
clbaddd 2005-09-23
  • 打赏
  • 举报
回复
研究一下

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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