I have a global DataSet called ds_SortPlan that I am using to map strings that match a certain regex pattern to an integer.
Private Function MatchDestination(ByVal code As String) As Integer
Dim m As Match
For Each tempRow As Data.DataRow In ds_SortPlan.Tables("MatchCode_Lookup").Rows
m = Regex.Match(code, tempRow.Item("Match_String"))
If m.Success Then
Return tempRow.Item("ID")
Exit Function
End If
Next tempRow
Return 0
End Function
This seem like a very slow and clunky way of doing this. 🙁
Is there a better way to set up a regex that will take a String code and try to match it against multiple patterns returning an associated ID number.
I would like to keep the DataSet if at all possible since there are lots of dependencies on it.
Any advice is appreciated!
If you are calling this function often, you could store the patterns and reuse them, instead of reading them from the DB each time
Note: You don’t need
Exit FunctionafterReturn.Returnreplaces the oldExit Functionfrom VB6.