文本提取字符串问题 有一大串字符,放在一个文本中想找到一行中含有"session"的行,就找前面行中,离这一行最近的含有"interface"的字符串,写入另外一个文本文件中,如何做? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 從前向後逐行讀取,寫入數組,并判斷是否包含session,包含則停止讀取并向前遍曆數組,找到第一個包含interface的成員 具体的文本?貌似Substring(),IndexOf()应该就可以解决问题了.. 类似于这样! interface gigabitEthernet 2/1.100 vlan id 100 ip description ydl_lan_3550_1 ip address 61.177.93.225 255.255.255.252! interface gigabitEthernet 2/1.159! interface gigabitEthernet 2/1.167 vlan id 167 ip unnumbered loopback 6! interface gigabitEthernet 2/1.1000 vlan id 1000 pppoe pppoe sessions 5 pppoe auto-configure pppoe profile any multicast! interface gigabitEthernet 2/1.11502 svlan id 115 2 svlan ethertype 8100 pppoe pppoe sessions 1 pppoe auto-configure pppoe profile any pppoe! interface gigabitEthernet 2/1.11503 svlan id 115 3 svlan ethertype 8100 pppoe pppoe sessions 1 pppoe auto-configure pppoe profile any pppoe! string input=".....";//你自己写读文本的代码Regex reg=new Regex(@"\s?(interface\s[^\n]+)(?:(?!\sinterface\s|\ssessions\s).)*\ssessions\s");StringBuilder sb=new StringBuild();foreach(Match m in reg.Matches(input)){ sb.AppendLine(m.Groups[1].Value);}string output=sb.ToString();//结果 C# 如何求一定范围不重复随机小数 C#在图片上添加文字后,用CorelDraw打开并能编辑 大侠们快来帮忙啊~来的通通给分 socket有几个版本?各个版本之间有什么区别?高人指点 如何做到复制表后 自增列值与原表一致 怎么修改继承窗体中的DataGridView控件的属性 web.config中采用forms验证时,如果使一些aspx不必验证?求高手解答。。 水晶报表显示图片的问题? 求解释? C# 求一正则表达式得到固定标签中的内容 **Delegate为什么不可以定义重载方法的签名。 能否用正则表达式控制 ?
貌似Substring(),IndexOf()应该就可以解决问题了..
!
interface gigabitEthernet 2/1.100
vlan id 100
ip description ydl_lan_3550_1
ip address 61.177.93.225 255.255.255.252
!
interface gigabitEthernet 2/1.159
!
interface gigabitEthernet 2/1.167
vlan id 167
ip unnumbered loopback 6
!
interface gigabitEthernet 2/1.1000
vlan id 1000
pppoe
pppoe sessions 5
pppoe auto-configure
pppoe profile any multicast
!
interface gigabitEthernet 2/1.11502
svlan id 115 2
svlan ethertype 8100
pppoe
pppoe sessions 1
pppoe auto-configure
pppoe profile any pppoe
!
interface gigabitEthernet 2/1.11503
svlan id 115 3
svlan ethertype 8100
pppoe
pppoe sessions 1
pppoe auto-configure
pppoe profile any pppoe
!
Regex reg=new Regex(@"\s?(interface\s[^\n]+)(?:(?!\sinterface\s|\ssessions\s).)*\ssessions\s");
StringBuilder sb=new StringBuild();
foreach(Match m in reg.Matches(input)){
sb.AppendLine(m.Groups[1].Value);
}
string output=sb.ToString();//结果