Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9219341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:05:38+00:00 2026-06-18T03:05:38+00:00

I have a global DataSet called ds_SortPlan that I am using to map strings

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:05:39+00:00Added an answer on June 18, 2026 at 3:05 am

    If you are calling this function often, you could store the patterns and reuse them, instead of reading them from the DB each time

    Private Function MatchDestination(ByVal input As String) As Integer
        Static patterns As List(Of KeyValuePair(Of Integer, String))
    
        If patterns Is Nothing Then
            patterns = New List(Of KeyValuePair(Of Integer, String))
            For Each row As DataRow In ds_SortPlan.Tables("MatchCode_Lookup").Rows
                Dim entry = New KeyValuePair(Of Integer, String)( _
                    DirectCast(row.Item("ID"), Integer), _
                    DirectCast(row.Item("Match_String"), String) _
                )
                patterns.Add(entry)
            Next
        End If
    
        For Each pattern As KeyValuePair(Of Integer, String) In patterns
            If Regex.IsMatch(input, pattern.Value) Then
                Return pattern.Key
            End If
        Next
        Return 0
    End Function
    

    Note: You don’t need Exit Function after Return. Return replaces the old Exit Function from VB6.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a strongly-typed dataset that is using DBDirectMethods to insert data into a
I have some designer generated code that I am using to query a dataset.
If i have global variable in A.dll, that depends on global variable in B.dll
I have a global variable averagel that I am trying to manipulate in a
I have a global header and footer that has a Database connection and a
I have a global variable that is an instance of my custom class. How
I have a python program with a global function that is painful to test
Does PHP have global variables that can be modified by one running script and
I've got a bunch of strongly typed DataSet that each have two tables. One
I've been getting some odd behavior using a foreach today. I have a dataset

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.