有关正则表达式的使用方法
vb2010吧
全部回复
仅看楼主
level 6
我发现匹配到了一个字符串之后没办法放到Text里。。因为匹配得到的字符串的类型是Object不能转换成String...
求高人解释
2012年04月29日 04点04分 1
level 9
你怎么弄的?
2012年04月29日 05点04分 2
level 13
Object类型.ToString()

Convert.ToString(Object类型)
2012年04月29日 07点04分 3
level 13
VB.NET 应该可以自动将 Object 转化为 String 。
如果 Object 不是字符串 (如图片) , 那就会错误。
一般都是 Convert.ToString ( Object ) 转换为 String .
2012年04月29日 08点04分 4
level 6
好吧 那matches怎么用
2012年04月29日 11点04分 5
level 13
Console:
Imports System.Text.RegularExpressions
Module Example
Public Sub Main()
Dim pattern As String = "\b\w+es\b"
Dim rgx As New Regex(pattern)
Dim sentence As String = "Who writes these notes?"
For Each match As Match In rgx.Matches(sentence)
Console.WriteLine("Found '{0}' at position {1}", match.Value, match.Index)
Next
End Sub
End Module
输出结果:
Found 'writes' at position 4
Found 'notes' at position 17
2012年04月30日 01点04分 6
level 13
正则表达式模式 Dim pattern As String = "\b\w+es\b" 的定义:
模式 说明
\b 在单词边界处开始匹配。
\w+ 匹配一个或多个单词字符。
es 匹配文本字符串“es”。
\b 在单词边界处结束匹配。
2012年04月30日 01点04分 7
level 13
我将这段控制台代码翻译为WinForm的,没发现什么问题
Imports System.Text.RegularExpressions
Public Class Example
Private Sub ButCS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButCS.Click
Dim pattern As String = "\b\w+es\b"
Dim rgx As New Regex(pattern)
Dim sentence As String = "Who writes these notes?"
For Each matchstring As Match In rgx.Matches(sentence)
MsgBox("Found '" & matchstring.Value & "' at position " & matchstring.Index)
Next
End Sub
End Class
2012年04月30日 01点04分 8
level 13
如果你是将匹配到的字符串放入到 TextBox 的 Text 属性里,那8L的代码只改 MsgBox("Found '" & matchstring.Value & "' at position " & matchstring.Index) 为 TextBox1.Text &= matchstring.Value & vbCrlf 即可
(注:控制台的代码和定义为MSDN里的 h t t p:/ / msdn.microsoft.c o m/zh-cn/library/system.text.regularexpressions.regex.matches . a s p x)

2012年04月30日 01点04分 9
level 6
老兄你发太快了吧....我得慢慢看....
2012年04月30日 01点04分 10
level 6
牛人- -谢了[Love]
2012年04月30日 01点04分 11
level 6
貌似VS2010的正则语法和标准的正则语法不同?
2012年04月30日 01点04分 12
level 13
两段代码已经VS2005测试通过.
MSDN里标明是.NET Framework 4,那应该支持VS2010。
2012年04月30日 01点04分 13
level 6
我拜您为师吧- -[Yeah]
2012年05月05日 14点05分 14
1