Instr from right

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve

    Instr from right

    I use the instr function frequently to find particular characters
    within a string and manipulate them eg all characters to the left of a
    particular character.
    If I understand correctly, Instr finds the first occurence of the
    nominated characater starting from the left of the subject field. Is
    there a way to do this but starting from the right of the field
    TIA
  • JohnH

    #2
    Re: Instr from right

    On May 20, 6:55 pm, Steve <stevecox4...@g mail.comwrote:
    I use the instr function frequently to find particular characters
    within a string and manipulate them eg all characters to the left of a
    particular character.
    If I understand correctly, Instr finds the first occurence of the
    nominated characater starting from the left of the subject field.  Is
    there a way to do this but starting from the right of the field
    TIA
    From:

    ---------------------------------------
    Routine: RevInStr
    Parameters: findin As String, tofind As String
    Description: Find a character in a string, only backwards

    Function RevInStr(findin As String, tofind As String) As Integer
    ' Chris Rae's VBA Code Archive - http://chrisrae.com/vba
    Dim findcha As Integer
    For findcha = Len(findin) - Len(tofind) + 1 To 1 Step -1
    If Mid(findin, findcha, Len(tofind)) = tofind Then
    RevInStr = findcha
    Exit Function
    End If
    Next findcha
    ' Defaults to zero anyway (tsk, tsk, etc)
    End Function
    ---------------------------------------

    Comment

    • fredg

      #3
      Re: Instr from right

      On Tue, 20 May 2008 18:55:01 -0700 (PDT), Steve wrote:
      I use the instr function frequently to find particular characters
      within a string and manipulate them eg all characters to the left of a
      particular character.
      If I understand correctly, Instr finds the first occurence of the
      nominated characater starting from the left of the subject field. Is
      there a way to do this but starting from the right of the field
      TIA
      Access 2000 or newer?
      Look up the InStrRev() function in VBA help.

      ?InStrRev("This is my place"," ")
      11

      ?Mid("This is my place",InStrRev ("This is my place"," ")+1)
      place


      --
      Fred
      Please respond only to this newsgroup.
      I do not reply to personal e-mail

      Comment

      • Tom van Stiphout

        #4
        Re: Instr from right

        On Tue, 20 May 2008 18:55:01 -0700 (PDT), Steve
        <stevecox4444@g mail.comwrote:

        In recent versions of Access you can use the InstrRev function,
        -Tom.

        >I use the instr function frequently to find particular characters
        >within a string and manipulate them eg all characters to the left of a
        >particular character.
        >If I understand correctly, Instr finds the first occurence of the
        >nominated characater starting from the left of the subject field. Is
        >there a way to do this but starting from the right of the field
        >TIA

        Comment

        Working...