在VB中读取文本文件(逐行)的不同规则 [英] Different rules to read a Text File (Line by Line) in VB

查看:296
本文介绍了在VB中读取文本文件(逐行)的不同规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下午好,

我正在使用Visual Studio 2010,需要逐行读取一个文本文件,并将每一行与一组规则进行比较(其中一些规则取决于其他规则).

我的想法是:我从将近500台Cisco设备(路由器,交换机,IPS,防火墙)中获取配置,并将配置与一组规则进行比较,具体取决于硬件和每个命令的用途.

如何创建带有变量的规则集,例如如果以...开头",如果以...结尾"或如果包含"等等,但是我可以在不修改源代码的情况下添加新规则(我不知道(如果我很清楚),但是就像一个ListBox,可以在其中添加/删除/修改规则,还有一个可以理解这些规则的大脚本?

任何帮助将不胜感激!


-------修改:

如果您知道先前创建的脚本,该脚本允许创建"语言"以根据可修改的规则集比较文本字符串,那就太棒了!

Good afternoon,

I am working with Visual-Studio 2010 and I need to read one text file line by line and compare each line to some set of rules (some of these depend of others).

The idea is: I am taking the configuration from almost 500 Cisco equipments (Routers, Switches, IPS, Firewalls) and compare the configurations with a set of rules depending on the Hardware and the purpose for each command.

How can I create a set of rules with variables such as "If Begin with" or "If end with" or "If contains" and so on but that I can add new rules WITHOUT modifying the source code (I don''t know if I am clear) but having like a ListBox where I can add/delete/modify the rules, and one big script that can understand these rules?

Any help will be appreciated!


------- Modify:

If you know of a script previously created that allows to "Create" a "Language" to compare text strings according a modifyble set of rules, it will be awesome!

推荐答案

我认为Regex类是您最好的朋友:在其
I think the Regex class is your best friend: have a look at the "Remarks" section in its documentation page[^].


也许一个简单的例子可以帮助您理解我:

我收到了这段文字:

Cisco自适应安全设备软件版本8.0(5)
设备管理器版本6.3(1)

由builders于2009年11月2日星期一21:22编译
系统映像文件为"disk0:/asa805-k8.bin"


而我需要逐行:

第一行:如果第一个字符是"Cisco Adaptative Security Appl ...",则在版本"之后打印并打印.
第二行:与6.3(1)相同
忽略第三和第四
第五行:取系统映像文件名(在之间"),不带.

在某些情况下,我需要同时验证三到四件事.
Perhaps a quick example will help you to understand me:

I got this text:

Cisco Adaptive Security Appliance Software Version 8.0(5)
Device Manager Version 6.3(1)

Compiled on Mon 02-Nov-09 21:22 by builders
System image file is "disk0:/asa805-k8.bin"


And line by line I will need:

1st line: "If the first characters are "Cisco Adaptative Security Appl..." take the part after "Version" and print.
2nd line: The same with the 6.3(1)
Ignore 3rd and 4th
5th Line: take System Image Filename (between ") without the ".

And in some lines I will need to validate three or four things at the same time.


这篇关于在VB中读取文本文件(逐行)的不同规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆