[AccessD] Last occurrence within a string

Heenan, Lambert Lambert.Heenan at AIG.com
Tue Oct 26 12:31:50 CDT 2004


Or, starting at the right end of the string (as that's where we are
expecting to see the data)

Function InStrR(varText As Variant, strFind As String) As Integer
   Dim n As Integer, nStart As Integer
    n = Len(strFind)
    If IsNull(varText) Or n = 0 Then
        InStrR = 0
        Exit Function
    End If
    nStart = Len(varText) - n
    While nStart > 0
        n = InStr(nStart, varText, strFind)
        If n = 0 Then
            nStart = nStart - 1
        Else
            InStrR = n
            Exit Function
        End If
    Wend
    InStrR = 0
End Function


Lambert

> -----Original Message-----
> From:	accessd-bounces at databaseadvisors.com
> [SMTP:accessd-bounces at databaseadvisors.com] On Behalf Of Vincent Pusateri
> Sent:	Tuesday, October 26, 2004 11:45 AM
> To:	'Access Developers discussion and problem solving'
> Subject:	RE: [AccessD] Last occurrence within a string
> 
> Here you go
> 
> Public Function GetEndString(vntString As Variant, strSymbol As String) As
> String
> 
>     Dim intStartPosition As Integer
>     Dim intSymbolPosition As Integer
>     
>     ' Loop through the line, looking for the last occurrence
>     ' of the symbol.  Once the last symbol as been found, pass
>     ' back the string to the right of it.
>     
>     intStartPosition = 1
>     
>     Do
>         intSymbolPosition = InStr(intStartPosition, vntString, strSymbol)
>         If intSymbolPosition > 0 Then
>             intStartPosition = intSymbolPosition + 1
>         End If
>     Loop Until intSymbolPosition = 0
>     
>     GetEndString = Trim$(Mid(vntString, intStartPosition))
>    
> End Function 
> 
> Vinnie Chas
> 
> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com
> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of ACTEBS
> Sent: Tuesday, October 26, 2004 7:08 AM
> To: Access Group (E-mail)
> Subject: [AccessD] Last occurrence within a string
> 
> Guys,
> 
> I am stuffing around with this and am sure I have done this before but for
> the life of me can't get it. I need to find the last occurrence of "\"
> within a file path string. For example if the path was
> C:\MyDocs\Docs\Temps\Hello.doc I want to be able to return the Hello.doc
> portion and to do that obviously I need to know what position the last
> backslash is.
> 
> Any ideas?
> 
> Vlad
> --
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> 
> 
> 
> 
> -- 
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com



More information about the AccessD mailing list