Arrrgh!! No 'reverse' InStr!!?? 
Author Message
 Arrrgh!! No 'reverse' InStr!!??

I really need a function like InStr that will search a string in reverse!!
(There is none as far as I can tell)

Instead of just finding the first occurrance of a string within a string - I
need to find the *last* occurence of a string within a string!

How can you search strings from end to beginning without taking a major
performance hit???



Sat, 02 Sep 2000 03:00:00 GMT  
 Arrrgh!! No 'reverse' InStr!!??


says...

Quote:
> I really need a function like InStr that will search a string in reverse!!
> (There is none as far as I can tell)

> Instead of just finding the first occurrance of a string within a string - I
> need to find the *last* occurence of a string within a string!

> How can you search strings from end to beginning without taking a major
> performance hit???

very easy, something like this

dim source as string
dim pos as integer
dim tmpstring as string
dim searchcriteria as string
dim counter as integer

for counter = 1 to len(source)
        tmpstring = mid(source,len(source) - counter,1) 'check the syntax
                                                                'here, you get the
                                                                'idea
        if tmpstring = searchcriteria then
                pos = counter
        end if
next

or

just do an instr() until and keep track of the last positon until it
returns ZERO which will indicate no more occurances.
last found = last position. and you get a total count in the bargain.
--
jarrodr (at) province (dot) com



Sat, 02 Sep 2000 03:00:00 GMT  
 Arrrgh!! No 'reverse' InStr!!??

Easier if you use:

For Counter = Len(Source) To 1 Step -1
    If SearchCharacter = Mid$(Source, Counter, 1) Then
        Exit For
    End If
Next

Counter will hold the specified character

Quote:
>for counter = 1 to len(source)
> tmpstring = mid(source,len(source) - counter,1) 'check the syntax
> 'here, you get the
> 'idea
> if tmpstring = searchcriteria then
> pos = counter
> end if
>next

>or

>just do an instr() until and keep track of the last positon until it
>returns ZERO which will indicate no more occurances.
>last found = last position. and you get a total count in the bargain.
>--
>jarrodr (at) province (dot) com



Sun, 03 Sep 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. InStr(cC(i), '/') vs InStr(cC(i), "/")

2. Reverse INSTR

3. Reverse INSTR for PB3.5

4. Why won't INSTR() work!!???

5. InStr doesn't work correctly in PowerPoint 97

6. INSTR and it's uses

7. Why doesn't this InStr syntax work?

8. Why doesn't this InStr work?

9. InStr Syntax doesn't work.

10. InStr syntax doesn't work

11. Why doesn't this InStr Syntax work?

 

 
Powered by phpBB® Forum Software