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

  • Home
  • SEARCH
  • 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 6070561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:56:51+00:00 2026-05-23T09:56:51+00:00

I’m trying to extract all rows from a datatable where CODE follows the pattern

  • 0

I’m trying to extract all rows from a datatable where “CODE” follows the pattern “Z##A”. I tried the following to no avail:

Dim floods() As DataRow = arqTable.Select("mid(code,1,1)='Z' and isnumeric(mid(code,2,2)) and mid(code,4,1)='A'")

An error returned

“The expression contains undefined
function call mid().”

I could go through the rows using a FOR EACH loop but I’m just curious if there is a way to simply use the datatable select function.

*Edit: BTW, using “code like ‘Z%A'” is not going to work as I’m specifically looking for Z[number][number]A and not ones with Z[letter][letter]A.

  • 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-05-23T09:56:51+00:00Added an answer on May 23, 2026 at 9:56 am

    This one works

    Dim r1() As DataRow = dt.Select("code LIKE 'Z%' and code LIKE '%A' and substring(code, 2, 1) >=  '0'  and substring(code, 2, 1) <= '9' and substring(code, 3, 1) >= '0' AND substring(code, 3, 1) <= '9' and len(code) =  4 ")
    

    If your at all concerned about efficiency check out this quick example as a point of interest from a performance perspective. (paste into a console application).

    Results…

    1000 RECORDS...
    SELECT: 00:00:00.0050357 matches 141
    VBLIKE: 00:00:00.0021198 matches 141 - %250.0
    VBRAW: 00:00:00.0007444 matches 141 - Infinity
    CREGEX: 00:00:00.0014745 matches 141 - %500.0
    
    10000 RECORDS...
    SELECT: 00:00:00.0530854 matches 1430
    VBLIKE: 00:00:00.0280535 matches 1430 - %189.3
    VBRAW: 00:00:00.0067957 matches 1430 - %883.3
    CREGEX: 00:00:00.0026389 matches 1430 - %2650.0
    
    100000 RECORDS...
    SELECT: 00:00:00.6141986 matches 13929
    VBLIKE: 00:00:00.1773157 matches 13929 - %346.9
    VBRAW: 00:00:00.0699633 matches 13929 - %889.9
    CREGEX: 00:00:00.0271444 matches 13929 - %2274.1
    
    1000000 RECORDS...
    SELECT: 00:00:06.2316807 matches 138987
    VBLIKE: 00:00:01.7882370 matches 138987 - %348.5
    VBRAW: 00:00:00.7093068 matches 138987 - %878.8
    CREGEX: 00:00:00.2714249 matches 138987 - %2299.3
    

    Code

    Imports System.Text.RegularExpressions
    
    Module Module1
    
        Public RegEx_Code As New Regex("^Z[0-9][0-9]A$", RegexOptions.Compiled)
    
        Sub Main()
            Dim trials() As Integer = {1000, 10000, 100000, 1000000} 'data sizes to test
            For Each recCnt As Integer In trials
                'build test data that is sort of similar.
                Dim dt As New DataTable
                dt.Columns.Add("code", GetType(String))
                For iQ As Integer = 0 To recCnt - 1
                    dt.Rows.Add(If(iQ Mod 4 = 0, "Z", "X") & Chr(Int(Rnd() * 15) + 48) & Chr(Int(Rnd() * 12) + 48) & If(iQ Mod 2 = 0, "A", "Y"))
                Next
    
                'test SELECT
                Dim sw1 As Stopwatch = Stopwatch.StartNew
                Dim r1() As DataRow = dt.Select("code LIKE 'Z%' and code LIKE '%A' and substring(code, 2, 1) >=  '0'  and substring(code, 2, 1) <= '9' and substring(code, 3, 1) >= '0' AND substring(code, 3, 1) <= '9' and len(code) =  4 ")
                sw1.Stop()
    
                'test VB built in LIKE
                Dim sw2 As Stopwatch = Stopwatch.StartNew
                Dim r2 As New List(Of DataRow)(recCnt \ 20)
                Dim rInd2 As Integer = dt.Columns("code").Ordinal
                For Each r As DataRow In dt.Rows
                    If CStr(r(rInd2)) Like "Z##A" Then
                        r2.Add(r)
                    End If
                Next
                r2.TrimExcess()
                sw2.Stop()
    
                Dim sw3 As Stopwatch = Stopwatch.StartNew
                Dim r3 As New List(Of DataRow)(recCnt \ 20)
                Dim rInd3 As Integer = dt.Columns("code").Ordinal
                For Each r As DataRow In dt.Rows
                    Dim value As String = CStr(r(rInd3))
                    If value.Length = 4 AndAlso IsNumeric(value.Substring(1, 1)) AndAlso IsNumeric(value.Substring(2, 1)) AndAlso value.StartsWith("Z") AndAlso value.EndsWith("A") Then
                        r3.Add(r)
                    End If
                Next
                r3.TrimExcess()
                sw3.Stop()
    
                'test Compiled Regular Expression.
                Dim sw4 As Stopwatch = Stopwatch.StartNew
                Dim r4 As New List(Of DataRow)(recCnt \ 20)
                Dim rInd4 As Integer = dt.Columns("code").Ordinal
                For Each r As DataRow In dt.Rows
                    If RegEx_Code.IsMatch(CStr(r(rInd4))) Then
                        r4.Add(r)
                    End If
                Next
                r4.TrimExcess()
                sw4.Stop()
                Console.WriteLine(recCnt & " RECORDS...")
                Console.WriteLine("SELECT: " & sw1.Elapsed.ToString & " matches " & r1.Length)
                Console.WriteLine("VBLIKE: " & sw2.Elapsed.ToString & " matches " & r2.Count & " - " & CDbl(sw1.ElapsedMilliseconds / sw2.ElapsedMilliseconds).ToString("%0.0"))
                Console.WriteLine("VBRAW: " & sw3.Elapsed.ToString & " matches " & r3.Count & " - " & CDbl(sw1.ElapsedMilliseconds / sw3.ElapsedMilliseconds).ToString("%0.0"))
                Console.WriteLine("CREGEX: " & sw4.Elapsed.ToString & " matches " & r3.Count & " - " & CDbl(sw1.ElapsedMilliseconds / sw4.ElapsedMilliseconds).ToString("%0.0"))
                Console.WriteLine()
    
            Next
    
            Console.ReadLine()
        End Sub
    
    End Module
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I have just tried to save a simple *.rtf file with some websites and
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.