<%
function FSOlinedit(filename,starNum,endnum)
if starNum < 1 then exit function
dim fso,f,temparray,tempcnt
set fso = server.CreateObject("scripting.filesystemobject")
if not fso.fileExists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(filename),1)
if not f.AtEndofStream then
tempcnt = f.readall
f.close
set f = nothing
temparray = split(tempcnt,chr(13)&chr(10))
if starNum>ubound(temparray)+1 then
exit function
else
i=starNum
for j=i to endnum
a =a&temparray(j-1)&","
next
FSOlinedit=a
end if
end if
end function
b=split(FSOlinedit("test.txt",5,8) ,",")
for i=0 to 4
response.Write b(i)&" "
next
%>
function FSOlinedit(filename,starNum,endnum)
if starNum < 1 then exit function
dim fso,f,temparray,tempcnt
set fso = server.CreateObject("scripting.filesystemobject")
if not fso.fileExists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(filename),1)
if not f.AtEndofStream then
tempcnt = f.readall
f.close
set f = nothing
temparray = split(tempcnt,chr(13)&chr(10))
if starNum>ubound(temparray)+1 then
exit function
else
i=starNum
for j=i to endnum
a =a&temparray(j-1)&","
next
FSOlinedit=a
end if
end if
end function
b=split(FSOlinedit("test.txt",5,8) ,",")
for i=0 to 4
response.Write b(i)&" "
next
%>
主要使用了FSO的Readall方法用于返回整个文件的内容,并用temparray = split(tempcnt,chr(13)&chr(10))
拆分赋给新的数组
然后利用循环读取指定的行数
本文介绍了一种使用FSO(File System Object)读取指定范围行数据的方法。通过VBScript实现,详细展示了如何利用FSO的ReadAll方法获取整个文件内容,再通过字符串处理技术精确提取所需行。

4665

被折叠的 条评论
为什么被折叠?



