如何在文本文件中搜索字符串模式?

时间:2011-10-11 01:20:50

标签: vbscript

我正在使用VbScript在以下示例输出的文本文件中进行搜索:

我的目标是仅从以下示例输出中检索文件路径。请注意,控件ID是固定的,其他所有内容都是动态的。有人帮帮忙吗?谢谢!

~~~~~~~~~~~~~~
============================
Control 127256:
name;db_size;owner;dbid;created;status;compatibility_level
----;-------;-----;----;-------;------;-------------------
master;      4.75 MB;sa;1;Apr  8 2003;Status=ONLINE, Updateability=READ_WRITE, UserAccess=MULTI_USER, Recovery=SIMPLE, Version=661, Collation=SQL_Latin1_General_CP1_CI_AS, SQLSortOrder=52, IsAutoCreateStatistics, IsAutoUpdateStatistics;100

name;fileid;filename;filegroup;size;maxsize;growth;usage
----;------;--------;---------;----;-------;------;-----
master;1;c:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\master.mdf;PRIMARY;4096 KB;Unlimited;10%;data only
mastlog;2;c:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\mastlog.ldf;NULL;768 KB;Unlimited;10%;log only
name;db_size;owner;dbid;created;status;compatibility_level
----;-------;-----;----;-------;------;-------------------
tempdb;      2.75 MB;sa;2;Oct 11 2011;Status=ONLINE, Updateability=READ_WRITE, UserAccess=MULTI_USER, Recovery=SIMPLE, Version=661, Collation=SQL_Latin1_General_CP1_CI_AS, SQLSortOrder=52, IsAutoCreateStatistics, IsAutoUpdateStatistics;100

name;fileid;filename;filegroup;size;maxsize;growth;usage
----;------;--------;---------;----;-------;------;-----
tempdev;1;c:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\tempdb.mdf;PRIMARY;2048 KB;Unlimited;10%;data only
templog;2;c:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\templog.ldf;NULL;768 KB;Unlimited;10%;log only
name;db_size;owner;dbid;created;status;compatibility_level
----;-------;-----;----;-------;------;-------------------
model;      1.75 MB;sa;3;Apr  8 2003;Status=ONLINE, Updateability=READ_WRITE, UserAccess=MULTI_USER, Recovery=SIMPLE, Version=661, Collation=SQL_Latin1_General_CP1_CI_AS, SQLSortOrder=52, IsAutoCreateStatistics, IsAutoUpdateStatistics;100

name;fileid;filename;filegroup;size;maxsize;growth;usage
----;------;--------;---------;----;-------;------;-----
modeldev;1;c:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\model.mdf;PRIMARY;1280 KB;Unlimited;1024 KB;data only
modellog;2;c:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\modellog.ldf;NULL;512 KB;Unlimited;10%;log only
name;db_size;owner;dbid;created;status;compatibility_level
----;-------;-----;----;-------;------;-------------------
msdb;     12.63 MB;sa;4;Apr  2 2010;Status=ONLINE, Updateability=READ_WRITE, UserAccess=MULTI_USER, Recovery=SIMPLE, Version=661, Collation=SQL_Latin1_General_CP1_CI_AS, SQLSortOrder=52, IsAutoCreateStatistics, IsAutoUpdateStatistics, IsFullTextEnabled;100

name;fileid;filename;filegroup;size;maxsize;growth;usage
----;------;--------;---------;----;-------;------;-----
MSDBData;1;c:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\MSDBData.mdf;PRIMARY;12416 KB;Unlimited;10%;data only
MSDBLog;2;c:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\MSDBLog.ldf;NULL;512 KB;2147483648 KB;10%;log only
~~~~~~~~~~~~~~
============================
Control 127257:

1 个答案:

答案 0 :(得分:1)

到目前为止你尝试了什么?

我首先从文本文件中读取测试(逐行或全部一次),然后在文本上拼写文本;

inputTextSplit = Split(1,inputText,“;”)

然后,您可以遍历数组并查找指示它是文件路径。例如以c:开头或包含\

对于i = 0到UBound(inputTestSplit)

循环