Results 1 to 5 of 5
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    function to extract numbers from string

    What is the simplest way to extract numbers form a string?

    e.g.

    jimbo4foo5

    to return



    45

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The only way that comes immediately to mind is a function that checked each character and only passed the numeric ones.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Depends on where you're trying to do it, but in VBA code here's one approach, where String2Parse is just that:

    Code:
    Private Sub String2Parse_AfterUpdate()
     
     Dim i As Integer
     
     Dim ParsedNumber As String
     
     If Not IsNull(Me.String2Parse) Then
     
      For i = 1 To Len(Me.String2Parse)
     
       If Mid(Me.String2Parse, i, 1) Like "[0-9]" Then
         ParsedNumber = ParsedNumber & Mid(Me.String2Parse, i, 1)
       End If
     
      Next i
     
      MsgBox ParsedNumber
    
     End If
     
    End Sub

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Thanks - I will use that in the future. That was sort of what I thought I would have to do (parse) except I was hoping for native access function

    anyway I used the left() function to extract the text of the name of the control then added the number using a counter x

    it let me cycle through 34 form controls (starting from 0) with the same name and iteration of x

    Works well

  5. #5
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    edit _

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Extract string before and after a period
    By bchi99 in forum Queries
    Replies: 3
    Last Post: 11-03-2014, 04:08 PM
  2. Extract part of string
    By Fais in forum Access
    Replies: 5
    Last Post: 08-06-2014, 04:46 PM
  3. Extract a number from a string
    By webisti in forum Access
    Replies: 3
    Last Post: 09-16-2013, 08:29 AM
  4. Extract Value from Variable in String
    By nguyenak in forum Programming
    Replies: 3
    Last Post: 05-24-2012, 03:50 PM
  5. Extract numbers from text string strored in a field.
    By khabdullah in forum Programming
    Replies: 2
    Last Post: 12-23-2007, 06:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums