返回列表 发帖

[问题求助] [已解决]vbs 怎么提取txt 文件中的指定行?

本帖最后由 pcl_test 于 2016-11-8 14:28 编辑

比方说有个文件1.txt 里有1000行, 我怎么提取出整百行文字, 如100,200.....
并且同时打印在vbs 窗口上;
以下只能显示单行:
dim title,y
title = CreateObject("scripting.filesystemobject").opentextfile("d:1.txt").readall
y=split(title,vbcrlf)
MsgBox y(14)
1

评分人数

    • Batcher: 感谢给帖子标题标注[已解决]字样PB + 2

本帖最后由 CrLf 于 2015-10-21 21:09 编辑
on error resume next
set fso = CreateObject("scripting.filesystemobject")
set ts = fso.opentextfile("d:\1.txt")
str = ""
do until ts.atendofstream
  for i=1 to 99
    ts.skipline
  next
  str = str & ts.readline & vbcrlf
loop
ts.close
msgbox strCOPY

TOP

本帖最后由 CrLf 于 2015-10-21 21:09 编辑
dim title,y
title = CreateObject("scripting.filesystemobject").opentextfile("d:1.txt").readall
y=split(title,vbcrlf)
stepnum=100
str = ""
for i=stepnum-1 to ubound(y) step stepnum
  str = str & y(i) & vbcrlf
next
msgbox strCOPY

TOP

回复 3# CrLf
谢谢老大,
如果用msgbox 的话, 能不能把每行的打印(100,200,300...) 打印在同一个msgbox,
或者直接将这些信息打印在vbs terminal 上, 我用的是secureCRT, 即 直接打印在secureCRT上.

TOP

已修改,如果用 WSH.Echo 代替 msgbox,在 cscript 宿主中可以输出到 console
1

评分人数

TOP

回复 5# CrLf


    谢谢 老大, 你的方法可行.

TOP

返回列表