用vb如何去掉每行<li></li>及其中内容?
用vb建立一个窗体,窗体上有两个文本框text1和text2(multiline均为true)、一个按钮command1。现在在text1中输入若干行代码(如下,每个代码...
用vb建立一个窗体,窗体上有两个文本框text1和text2(multiline均为true)、一个按钮command1。现在在text1中输入若干行代码(如下,每个代码一行),点击command1,自动在text2中去掉每行<li></li>及其属性内容。
在text1中输入的代码:
<LI sizcache="8" sizset="76"><A href="http://www.***.com" rel=www.***.com jQuery1271124061256="24">中国食用油网</A> </LI>
<LI sizcache="8" sizset="77"><A href="http://www.***.com/index.html?currently=home" rel=www.***..com jQuery1271124061256="25">某网</A> </LI>
<LI sizcache="8" sizset="78"><A href="http://www.***.com" rel=www.***..com jQuery1271124061256="26">某网</A> </LI>
处理结果如下 :
<A href="http://www.***.com" rel=www.***.com jQuery1271124061256="24">中国食用油网</A>
<A href="http://www.***.com/index.html?currently=home" rel=www.***..com jQuery1271124061256="25">大某网</A>
<A href="http://www.***.com" rel=www.***..com jQuery1271124061256="26">某网</A>
有时候输入的代码没有换行,可以加上删除换行符功能吗?比如:
<LI sizcache="8" sizset="70"><A href="http://ww.**.com/" rel=www.aa*.com
jQuery1271124061256="18">中农网</A> </LI> 展开
在text1中输入的代码:
<LI sizcache="8" sizset="76"><A href="http://www.***.com" rel=www.***.com jQuery1271124061256="24">中国食用油网</A> </LI>
<LI sizcache="8" sizset="77"><A href="http://www.***.com/index.html?currently=home" rel=www.***..com jQuery1271124061256="25">某网</A> </LI>
<LI sizcache="8" sizset="78"><A href="http://www.***.com" rel=www.***..com jQuery1271124061256="26">某网</A> </LI>
处理结果如下 :
<A href="http://www.***.com" rel=www.***.com jQuery1271124061256="24">中国食用油网</A>
<A href="http://www.***.com/index.html?currently=home" rel=www.***..com jQuery1271124061256="25">大某网</A>
<A href="http://www.***.com" rel=www.***..com jQuery1271124061256="26">某网</A>
有时候输入的代码没有换行,可以加上删除换行符功能吗?比如:
<LI sizcache="8" sizset="70"><A href="http://ww.**.com/" rel=www.aa*.com
jQuery1271124061256="18">中农网</A> </LI> 展开
展开全部
你的目的只是提取A标签的内容的话,不用管LI标签了,直接用正则很方便实现。
Private Sub Command1_Click()
Dim s As String
s = Text1.Text
s = Replace(Text1.Text, vbCrLf, "") '去除所有的回车
Dim oRegEx, oMatches
Dim Item
Set oRegEx = CreateObject("VBScript.RegExp")
With oRegEx
.Global = True
.IgnoreCase = True
.Pattern = "<a.*?\/a>" '提取所有A标签的正则表达式
Set oMatches = .Execute(s)
If oMatches.Count >= 1 Then
Text2.Text = ""
For Each Item In oMatches
Text2.Text = Text2.Text & Item & vbNewLine
Next
End If
End With
Set oMatches = Nothing
Set oRegEx = Nothing
End Sub
Private Sub Command1_Click()
Dim s As String
s = Text1.Text
s = Replace(Text1.Text, vbCrLf, "") '去除所有的回车
Dim oRegEx, oMatches
Dim Item
Set oRegEx = CreateObject("VBScript.RegExp")
With oRegEx
.Global = True
.IgnoreCase = True
.Pattern = "<a.*?\/a>" '提取所有A标签的正则表达式
Set oMatches = .Execute(s)
If oMatches.Count >= 1 Then
Text2.Text = ""
For Each Item In oMatches
Text2.Text = Text2.Text & Item & vbNewLine
Next
End If
End With
Set oMatches = Nothing
Set oRegEx = Nothing
End Sub
展开全部
Option Explicit
Private Sub command1_click()
Dim l&, r&, a, i&
Text2 = ""
a = Split(Text1, vbCrLf)
For i = 0 To UBound(a)
l = InStr(UCase$(a(i)), "<LI ")
If l > 0 Then
r = InStr(a(i), ">")
a(i) = Mid(a(i), r + 1)
l = InStr(UCase$(a(i)), "</LI>")
a(i) = Mid(a(i), 1, l - 1)
If a(i) <> "" Then Text2 = Text2 & a(i) & vbCrLf
End If
Next
End Sub
Private Sub command1_click()
Dim l&, r&, a, i&
Text2 = ""
a = Split(Text1, vbCrLf)
For i = 0 To UBound(a)
l = InStr(UCase$(a(i)), "<LI ")
If l > 0 Then
r = InStr(a(i), ">")
a(i) = Mid(a(i), r + 1)
l = InStr(UCase$(a(i)), "</LI>")
a(i) = Mid(a(i), 1, l - 1)
If a(i) <> "" Then Text2 = Text2 & a(i) & vbCrLf
End If
Next
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询