首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

截取字符串解决办法

2012-02-05 
截取字符串如何截取字符串“xxxx imgxx xxxx /img xxxxxx imgxx xxxx /img ”中 imgxx XXX /img

截取字符串
如何截取字符串“xxxx <img   xx> xxxx </img> xxxxxx <img   xx> xxxx </img> ”
中 <img   xx> XXX </img>
放入数组中。


[解决办法]
Dim doc As String = " " '需要验证的字符串
Dim f As New System.Text.RegularExpressions.Regex( " <img(? <body> [\s\S]*?) </img\> ")
Dim sum As Integer = f.Matches(doc).Count
Dim col As System.Text.RegularExpressions.MatchCollection = f.Matches(doc)
Dim temp(sum) As String
For i As Integer = 0 To col.Count - 1
temp(i) = col.Item(i).Groups(0).ToString
Next
[解决办法]
楼上的正则结果是没错。不过按你的意思,这样的正则更合适:
<img[^> ]*> (? <body> [\s\S]*?) </img\>
[解决办法]
我的办法,可能正则表达式不太对
MatchCollection rc=new Regex.Matches(@ " <img xx> [^ <> ]+ </img> ")
ArrayList al=new ArrayList();
foreach(Match m in mc)
{
al.Add(m.Value);
}

热点排行