Re: Searching from right - code mod please!

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Not sure that helps with the issue of no third forward slash.

I haven't tested the following very thoroughly, but I think it does what's
wanted:

Function RAT(strSearchIn As String, _
strDelimiter As String, _
occurences As Long _
) As Integer

Dim varInput As Variant

varInput = Split(strSearchIn, strDelimiter)
If occurences >= 0 And _
UBound(varInput) >= occurences Then
RAT = varInput(occurences)
End If

End Function

?Rat("1/2345/6/78", "/", 3)
78
?Rat("1/2345/6", "/", 3)
0



--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"KARL DEWEY" <KARLDEWEY@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:97E9CBCD-E2FC-4DFD-ADA5-00A17A07C3D8@xxxxxxxxxxxxxxxx
Without the code you can do it this way --
Mid([YourField], InstrRev([YourField], "/")+1)

InstrRev starts looking from right for the character and returns the
position from the left.

"andy.bayley@xxxxxxxxx" wrote:

Hi

I'm using this bit of code (thanks to Lyle Fairfield) to help me find
the text after the third forward slash in a field.
An example field may be 1/2345/6/78 - and I wish to return 78.
Please could someone let me know hot to amend this code so that if
there is no third forward slash, the function will return a zero?
Currently it returns some other number!

Function RAT(strSearchIn As String, strSearchFor As String, occurences
As Long)
As Integer
Dim aSearchIn() As Byte, intCounter As Integer, bytSearchFor As
Byte
Dim occurence As Long
For occurence = 1 To occurences
aSearchIn = StrConv(strSearchIn, vbFromUnicode)
bytSearchFor = Asc(strSearchFor)
For intCounter = UBound(aSearchIn) To LBound(aSearchIn) Step -1
If aSearchIn(intCounter) = bytSearchFor Then
RAT = intCounter + 1
Exit For
End If
Next intCounter
Next
End Function

Thanks!
Andy.



.



Relevant Pages

  • Searching from right - code mod please!
    ... the text after the third forward slash in a field. ... Function RAT(strSearchIn As String, strSearchFor As String, occurences ... Dim aSearchInAs Byte, intCounter As Integer, bytSearchFor As ...
    (microsoft.public.access.macros)
  • Re: # of occurences of string in another string
    ... int index = 0; ... That should get you the number of occurences correctly. ... > I wrote something a while back that stores the offset of all string> occurences within another string. ... Is there an easier/faster way to do>> it using regular expressions? ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Searching from right - code mod please!
    ... Function RAT(strSearchIn As String, strSearchFor As String, occurences ... Dim aSearchIn() As Byte, intCounter As Integer, bytSearchFor As ...
    (microsoft.public.access.macros)
  • String matching from dictionary in very large text
    ... I am working on one informatics problem and I am ... curious if it is possible to find all occurences of every word from a ... 5000-10000 each in text with length 5MB (the text is simply a string ... 1,4GHz Athlon, but it was incredibly slow for 5MB). ...
    (comp.programming)
  • Re: String search vs regexp search
    ... of occurences using string & regexp. ... I wrote the code for the regexp search as well as the function ... How long is the substring? ...
    (comp.lang.python)