|
s11ss
银牌会员
    
积分 2098
发帖 566
注册 2007-9-11
状态 离线
|
『楼 主』:
[求助]怎样用vbs代码实现查找和写出字符串?
使用 LLM 解释/回答一下
怎样用vbs代码实现查找某个文本文件中的某个字符串并写出到另一个文件?(输出包含该字符串的行)
Last edited by s11ss on 2007-12-14 at 04:24 PM ]
How to use VBS code to find a certain string in a text file and write it to another file? (Output the lines containing the string)
Last edited by s11ss on 2007-12-14 at 04:24 PM ]
|
|
2007-12-12 19:51 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
|
2007-12-12 20:47 |
|
|
s11ss
银牌会员
    
积分 2098
发帖 566
注册 2007-9-11
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
vkill兄知道不知道用cscript执行vbs时是否有类似cls的清屏命令?
Does Brother vkill know if there is a clear screen command similar to cls when executing VBS with cscript?
|
|
2007-12-12 21:10 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
Originally posted by s11ss at 2007-12-12 21:10:
vkill兄知道不知道用cscript执行vbs时是否有类似cls的清屏命令?
未知,好象除了cmd都没有清屏的功能吧
Originally posted by s11ss at 2007-12-12 21:10:
Does brother vkill know if there is a screen-clearing command similar to cls when executing vbs with cscript?
Unknown, it seems that except for cmd, there is no screen-clearing function.
|
|
2007-12-13 20:30 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
|
2007-12-13 20:48 |
|
|
jmz573515
银牌会员
    
积分 1212
发帖 464
注册 2006-12-13
状态 离线
|
|
2007-12-13 21:37 |
|
|
lotus516
高级用户
    论坛上抢劫的
积分 551
发帖 246
注册 2006-9-21
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
能不能把代码说详细些啊?
Can you explain the code in more detail?
|
|
2007-12-14 00:29 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
并不是真正的清屏,而是替换为空或者隐藏 
hta本身运行方式就和批处理不同
<html>
<title>cls</title>
<HTA:APPLICATION
ID="MyhyliApp"
APPLICATIONNAME="cls"
BORDER="thin"
BORDERSTYLE="normal"
VERSION="1.0"
SCROLL="no"
INNERBORDER="yes"
CONTEXTMENU="yes"
CAPTION="yes"
MAXIMIZEBUTTON="yes"
MINIMIZEBUTTON="yes"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="normal"
NAVIGABLE="yes"
/>
<script language="VBScript">
windowswidth = 640
windowsheight = 480
window.resizeTo windowswidth, windowsheight
ileft=(window.screen.width-windowswidth)/2
itop=(window.screen.height-windowsheight)/2
window.moveTo ileft,itop
</script>
<body bgcolor=#e0e0e0>
<table align="center">
<tr>
<td align="center">清除后用F5刷新</td>
</tr>
<tr>
<td id="Menu" align="center"></td>
</tr>
</table>
<table width="100%" style="position:absolute; bottom:20px;"><td>
<table align="center" style="font:bold 15px 宋体;">
<tr align="center">
<td><button onclick="CLS1" style="width:100;">清除内容</button></td>
</tr>
<tr align="center">
<td><button onclick="CLS2" style="width:100;">隐藏内容</button></td>
</tr>
</table>
</td></table>
</body>
<script language="VBScript">
Menu.innerHTML = "测试<br>测试<br>测试<br>测试<br>测试<br>"
Sub CLS1
Menu.innerHTML = ""
End Sub
Sub CLS2
Menu.style.display = "none"
End Sub
</script>
<html>
It's not really clearing the screen, but replacing it with empty or hiding
The running mode of HTA itself is different from batch processing
<html>
<title>cls</title>
<HTA:APPLICATION
ID="MyhyliApp"
APPLICATIONNAME="cls"
BORDER="thin"
BORDERSTYLE="normal"
VERSION="1.0"
SCROLL="no"
INNERBORDER="yes"
CONTEXTMENU="yes"
CAPTION="yes"
MAXIMIZEBUTTON="yes"
MINIMIZEBUTTON="yes"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="normal"
NAVIGABLE="yes"
/>
<script language="VBScript">
windowswidth = 640
windowsheight = 480
window.resizeTo windowswidth, windowsheight
ileft=(window.screen.width-windowswidth)/2
itop=(window.screen.height-windowsheight)/2
window.moveTo ileft,itop
</script>
<body bgcolor=#e0e0e0>
<table align="center">
<tr>
<td align="center">Clear and then refresh with F5</td>
</tr>
<tr>
<td id="Menu" align="center"></td>
</tr>
</table>
<table width="100%" style="position:absolute; bottom:20px;"><td>
<table align="center" style="font:bold 15px 宋体;">
<tr align="center">
<td><button onclick="CLS1" style="width:100;">Clear Content</button></td>
</tr>
<tr align="center">
<td><button onclick="CLS2" style="width:100;">Hide Content</button></td>
</tr>
</table>
</td></table>
</body>
<script language="VBScript">
Menu.innerHTML = "Test<br>Test<br>Test<br>Test<br>Test<br>"
Sub CLS1
Menu.innerHTML = ""
End Sub
Sub CLS2
Menu.style.display = "none"
End Sub
</script>
<html>
|

 |
|
2007-12-14 02:09 |
|
|
fastslz
铂金会员
       DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
指定1个字符
file=Wscript.ScriptFullName
'file=WScript.Arguments(0)
Dim str
set str = CreateObject("Adodb.Stream")
str.Type = 1
str.Mode = 3
str.Open
str.Loadfromfile file
Bin=str.read(6)
Usage = MidB(Bin,6,1)
str.Close
set str = Nothing
WScript.echo "本脚本第6字节字符为“",Usage,"”"
Specify 1 character
file=Wscript.ScriptFullName
'file=WScript.Arguments(0)
Dim str
set str = CreateObject("Adodb.Stream")
str.Type = 1
str.Mode = 3
str.Open
str.Loadfromfile file
Bin=str.read(6)
Usage = MidB(Bin,6,1)
str.Close
set str = Nothing
WScript.echo "The character at the 6th byte of this script is “",Usage,"”"
|

第一高手 第二高手
我的小站
 |
|
2007-12-14 15:00 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
问题是你要输出包含字符的那一行,还是有那个字符就输出那个字符?
The question is: Do you want to output the line that contains the character, or output that character if it exists?
|

 |
|
2007-12-14 15:39 |
|
|
s11ss
银牌会员
    
积分 2098
发帖 566
注册 2007-9-11
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
输出包含字符的那一行
Please provide the specific content from the China DOS Union (中国DOS联盟) forum so that I can accurately output the line containing characters.
|
|
2007-12-14 16:23 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
Set fso = CreateObject("Scripting.FileSystemObject")
source = "a.txt"
strFind = "b"
Set f = fso.OpenTextFile(source,1)
While not f.AtEndOfStream
strRead = f.ReadLine
If instr(strRead,strFind)>0 Then
msgbox strRead
End If
Wend
f.Close
```vb
Set fso = CreateObject("Scripting.FileSystemObject")
source = "a.txt"
strFind = "b"
Set f = fso.OpenTextFile(source, 1)
While Not f.AtEndOfStream
strRead = f.ReadLine
If InStr(strRead, strFind) > 0 Then
MsgBox strRead
End If
Wend
f.Close
```
|

 |
|
2007-12-14 16:42 |
|
|
fastslz
铂金会员
       DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
|
2007-12-14 17:03 |
|
|
terse
银牌会员
    
积分 2404
发帖 946
注册 2005-9-8
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
翻到个老贴发上来
set fso=createobject("scripting.filesystemobject")
If fso.FileExists("text.txt")=0 then '判断是否存在text.txt文件
fso.createtextfile("text.txt")
end if
set file=fso.opentextfile("text.txt",8) '追加形式打开文件
set opfile=fso.opentextfile("a.txt") '打开文件
do while opfile.atendofstream=false
line=opfile.readline '读取一行内容
if instr(line,"查找字符")>0 then '判断是否包含查找字符
str=str&line&vbcrlf '加入缓冲区
end if
loop
file.writeline (str) '搜索到查找字符行写入text.txt文件
Dig out an old post and post it up
set fso=createobject("scripting.filesystemobject")
If fso.FileExists("text.txt")=0 then 'Check if the text.txt file exists
fso.createtextfile("text.txt")
end if
set file=fso.opentextfile("text.txt",8) 'Open the file in append mode
set opfile=fso.opentextfile("a.txt") 'Open the file
do while opfile.atendofstream=false
line=opfile.readline 'Read a line of content
if instr(line,"Search character")>0 then 'Judge if it contains the search character
str=str&line&vbcrlf 'Add to buffer
end if
loop
file.writeline (str) 'Write the line with the search character to the text.txt file
|

简单!简单!再简单! |
|
2007-12-14 20:16 |
|
|
lotus516
高级用户
    论坛上抢劫的
积分 551
发帖 246
注册 2006-9-21
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
Originally posted by zh159 at 2007-12-14 16:42:
Set fso = CreateObject("Scripting.FileSystemObject")
source = "a.txt"
strFind = "b"
Set f = fso.OpenTextFile(source,1)
While not f.AtEndOfStream
strRe ...
如果有多个字符呢!!我有一个文本list.txt,里面有abc,will,www等等(均为一行一个单词),可不可以一起找出来呢?而不要运行VBS都要去重新给strFind赋值
Originally posted by zh159 at 2007-12-14 16:42:
Set fso = CreateObject("Scripting.FileSystemObject")
source = "a.txt"
strFind = "b"
Set f = fso.OpenTextFile(source,1)
While not f.AtEndOfStream
strRe ...
What if there are multiple characters!! I have a text file list.txt, which has abc, will, www, etc. (all one word per line). Can I find them all at once instead of having to reassign strFind every time I run the VBS?
|
|
2007-12-16 10:48 |
|