Regex.Matches返回类型

时间:2014-09-18 00:06:11

标签: vb.net visual-studio-2010 list

我的问题出在这一行:

Dim groups As List(Of String) = (From m In Regex.Matches(str, "\d{2}") m.Value).ToList()

此代码无法在vb.net中运行... m.value

这是我在vb.net中的代码......

Imports System.Text.RegularExpressions
Imports System.Collections.Generic

Public Class Form1

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

    Dim dezena As String = TextBox1.Text

    Dim strs As New List(Of String)() From { _
     "0203040610121415161727343738414246474852", _
     "0406080910111415273536394148495154565860", _
     "0709101416171819202229313943475354555758", _
     "0102030506080913151921232631343646505153", _
     "0106081213161925262930333840434757585960", _
     "0709121516192728303235444547505154555657", _
     "0308111316171821273235373840414344454952", _
     "0103040607091518222728303134363945465556", _
     "0406121316202225353637383942434445495660", _
     "0105070912141820212630373840434446525558", _
     "0105060714182325273031323436374548515556", _
     "0108141620222325263536394142444849505159" _
    }


    Dim linha As Integer = 1


    For Each str As String In strs
         'here is error line
         Dim groups As List(Of String) = (From m In Regex.Matches(str, "\d{2}") m.Value).ToList()

        If groups.Contains(dezena) Then
            ListBox1.Items.Add(linha)
        End If

        linha += 1
    Next

End Sub


End Class

2 个答案:

答案 0 :(得分:1)

您错过了Select关键字:

Dim groups As List(Of String) = _
  (From m In Regex.Matches(str, "\d{2}") Select DirectCast(m, Match).Value) _
  .ToList()

答案 1 :(得分:0)

正确的代码是:

Dim groups As List(Of Object) = (From m In Regex.Matches(str, "\d{2}") Select m.Value).ToList()