Question regarding the InStrRev Funciton. Does it really do any thing differnet to InStr??? 
Author Message
 Question regarding the InStrRev Funciton. Does it really do any thing differnet to InStr???

Hi there all,
            Here is something I have just come across that I can find no
logic for. The InStrRev Function.  I found this when looking in MSDN and
thought it would do exactly what it says.  :-(  However that dose not seem
to be the case.  They say in MSDN that The InStrRev Function:

"Returns the position of an occurrence of one string within another, from
the end of string."

Now I am assuming that the start of a string is the first character (one on
the far left) and the end of a string is the last (one on the far right).
If that is the case here is what I have found:

    MsgBox InStrRev("test file.txt", ".")
Returns the position value of 10

    MsgBox InStrRev("test file.txt", ".", Len("test file.txt"))
Returns the position value of 10

    MsgBox InStrRev("test file.txt", ".", -1, vbTextCompare)
Returns the position value of 10

    MsgBox InStrRev("test file.txt", ".", -1, vbBinaryCompare)
Returns the position value of 10

Now if InStrRev did what MSDN say that it is spost to you would think that
it would return the position of an occurrence of the "." within "test
file.txt", from the end of string (being the last character) as the value 4
considering that is correct!!!!
It is actually just doing exactly what InStr dose and starting from the
start of the string (the first character) and giving the result of the value
10 as the position.

Is it just me, or is InStrRev actually InStr in disguise..........
Has anyone else come up against this prob?
My work around was to just use StrReverse with InStr to get the correct
value of 4.

    MsgBox InStrRev(StrReverse("test file.txt"), ".")
Returns the position value of 4

I would be very interested to hear what others that have faced this dilemma
have done....

Thank you for your time,

Scott.



Thu, 07 Oct 2004 06:36:38 GMT  
 Question regarding the InStrRev Funciton. Does it really do any thing differnet to InStr???
 Try a string that has two search characters and you will see the difference

   MsgBox InStrRev("test.file.txt", ".")
   MsgBox InStr("test.file.txt", ".")

Probably a poor choice of wording in MSDN

David


Quote:
> Hi there all,
>             Here is something I have just come across that I can find no
> logic for. The InStrRev Function.  I found this when looking in MSDN and
> thought it would do exactly what it says.  :-(  However that dose not seem
> to be the case.  They say in MSDN that The InStrRev Function:

> "Returns the position of an occurrence of one string within another, from
> the end of string."

> Now I am assuming that the start of a string is the first character (one
on
> the far left) and the end of a string is the last (one on the far right).
> If that is the case here is what I have found:

>     MsgBox InStrRev("test file.txt", ".")
> Returns the position value of 10

>     MsgBox InStrRev("test file.txt", ".", Len("test file.txt"))
> Returns the position value of 10

>     MsgBox InStrRev("test file.txt", ".", -1, vbTextCompare)
> Returns the position value of 10

>     MsgBox InStrRev("test file.txt", ".", -1, vbBinaryCompare)
> Returns the position value of 10

> Now if InStrRev did what MSDN say that it is spost to you would think that
> it would return the position of an occurrence of the "." within "test
> file.txt", from the end of string (being the last character) as the value
4
> considering that is correct!!!!
> It is actually just doing exactly what InStr dose and starting from the
> start of the string (the first character) and giving the result of the
value
> 10 as the position.

> Is it just me, or is InStrRev actually InStr in disguise..........
> Has anyone else come up against this prob?
> My work around was to just use StrReverse with InStr to get the correct
> value of 4.

>     MsgBox InStrRev(StrReverse("test file.txt"), ".")
> Returns the position value of 4

> I would be very interested to hear what others that have faced this
dilemma
> have done....

> Thank you for your time,

> Scott.



Thu, 07 Oct 2004 06:51:19 GMT  
 Question regarding the InStrRev Funciton. Does it really do any thing differnet to InStr???

Quote:

> Hi there all,
>             Here is something I have just come across that I can find no
> logic for. The InStrRev Function.  I found this when looking in MSDN and
> thought it would do exactly what it says.  :-(  However that dose not seem
> to be the case.  They say in MSDN that The InStrRev Function:

> "Returns the position of an occurrence of one string within another, from
> the end of string."

> Now I am assuming that the start of a string is the first character (one on
> the far left) and the end of a string is the last (one on the far right).
> If that is the case here is what I have found:

>     MsgBox InStrRev("test file.txt", ".")
> Returns the position value of 10

As will this:  MsgBox InStrRev("test.file.txt", ".")

--
Joe Foster <mailto:jlfoster%40znet.com>     On the cans? <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!



Thu, 07 Oct 2004 06:57:47 GMT  
 Question regarding the InStrRev Funciton. Does it really do any thing differnet to InStr???
The POSITION that InStrRev returns is always from the beginning of the
string, just like InStr, regardless of everything else.  InStrRev just
starts *searching* from the end of the string whereas Instr starts
*searching* from the beginning of the string.

In the following, both InStr and InStrRev will return the same value....3.

Debug.Print InStr("C:\Test", "\")
Debug.Print InStrRev("C:\Test", "\")

In the following code, InStr will return 3 again, but InStrRev will return
15 (the position of the 3rd, and last, backslash).

Debug.Print InStr("C:\Test1\Test2\Test3", "\")
Debug.Print InStrRev("C:\Test1\Test2\Test3", "\")

Does it not seem logical to you that the position of the found character be
"referenced" from the beginning of the string?  It does to me.

Mike


Quote:
> Hi there all,
>             Here is something I have just come across that I can find no
> logic for. The InStrRev Function.  I found this when looking in MSDN and
> thought it would do exactly what it says.  :-(  However that dose not seem
> to be the case.  They say in MSDN that The InStrRev Function:

> "Returns the position of an occurrence of one string within another, from
> the end of string."

> Now I am assuming that the start of a string is the first character (one
on
> the far left) and the end of a string is the last (one on the far right).
> If that is the case here is what I have found:

>     MsgBox InStrRev("test file.txt", ".")
> Returns the position value of 10

>     MsgBox InStrRev("test file.txt", ".", Len("test file.txt"))
> Returns the position value of 10

>     MsgBox InStrRev("test file.txt", ".", -1, vbTextCompare)
> Returns the position value of 10

>     MsgBox InStrRev("test file.txt", ".", -1, vbBinaryCompare)
> Returns the position value of 10

> Now if InStrRev did what MSDN say that it is spost to you would think that
> it would return the position of an occurrence of the "." within "test
> file.txt", from the end of string (being the last character) as the value
4
> considering that is correct!!!!
> It is actually just doing exactly what InStr dose and starting from the
> start of the string (the first character) and giving the result of the
value
> 10 as the position.

> Is it just me, or is InStrRev actually InStr in disguise..........
> Has anyone else come up against this prob?
> My work around was to just use StrReverse with InStr to get the correct
> value of 4.

>     MsgBox InStrRev(StrReverse("test file.txt"), ".")
> Returns the position value of 4

> I would be very interested to hear what others that have faced this
dilemma
> have done....

> Thank you for your time,

> Scott.



Thu, 07 Oct 2004 07:15:23 GMT  
 Question regarding the InStrRev Funciton. Does it really do any thing differnet to InStr???
Thanks to all who have replied  :-)

I now have a better understanding of what they (MSDN) are saying....  same
function just starts from deferent end.

Scott.


Quote:
> Hi there all,
>             Here is something I have just come across that I can find no
> logic for. The InStrRev Function.  I found this when looking in MSDN and
> thought it would do exactly what it says.  :-(  However that dose not seem
> to be the case.  They say in MSDN that The InStrRev Function:

> "Returns the position of an occurrence of one string within another, from
> the end of string."

> Now I am assuming that the start of a string is the first character (one
on
> the far left) and the end of a string is the last (one on the far right).
> If that is the case here is what I have found:

>     MsgBox InStrRev("test file.txt", ".")
> Returns the position value of 10

>     MsgBox InStrRev("test file.txt", ".", Len("test file.txt"))
> Returns the position value of 10

>     MsgBox InStrRev("test file.txt", ".", -1, vbTextCompare)
> Returns the position value of 10

>     MsgBox InStrRev("test file.txt", ".", -1, vbBinaryCompare)
> Returns the position value of 10

> Now if InStrRev did what MSDN say that it is spost to you would think that
> it would return the position of an occurrence of the "." within "test
> file.txt", from the end of string (being the last character) as the value
4
> considering that is correct!!!!
> It is actually just doing exactly what InStr dose and starting from the
> start of the string (the first character) and giving the result of the
value
> 10 as the position.

> Is it just me, or is InStrRev actually InStr in disguise..........
> Has anyone else come up against this prob?
> My work around was to just use StrReverse with InStr to get the correct
> value of 4.

>     MsgBox InStrRev(StrReverse("test file.txt"), ".")
> Returns the position value of 4

> I would be very interested to hear what others that have faced this
dilemma
> have done....

> Thank you for your time,

> Scott.



Thu, 07 Oct 2004 07:38:28 GMT  
 Question regarding the InStrRev Funciton. Does it really do any thing differnet to InStr???
Of course. Suppose you want to find the extension of a file:
"test.file.txt.zip". With the InStr function you have to loop until
reached the last "." and then return the extension name of the file.
With the InStrRev you only have to perform it once to return the last
"."

strText="test.file.txt.zip"
intextpos=InStrRev(strText, ".")
strextname=right(strText,len(strText)-intextpos)

Cool

BD



Quote:
>The POSITION that InStrRev returns is always from the beginning of the
>string, just like InStr, regardless of everything else.  InStrRev just
>starts *searching* from the end of the string whereas Instr starts
>*searching* from the beginning of the string.

>In the following, both InStr and InStrRev will return the same value....3.

>Debug.Print InStr("C:\Test", "\")
>Debug.Print InStrRev("C:\Test", "\")

>In the following code, InStr will return 3 again, but InStrRev will return
>15 (the position of the 3rd, and last, backslash).

>Debug.Print InStr("C:\Test1\Test2\Test3", "\")
>Debug.Print InStrRev("C:\Test1\Test2\Test3", "\")

>Does it not seem logical to you that the position of the found character be
>"referenced" from the beginning of the string?  It does to me.

>Mike



Thu, 07 Oct 2004 07:40:05 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Question regarding the InStrRev Funciton. Does it really do any thing differnet to InStr???

2. Craziest thing you've done with VBA?

3. 1 button doing multiple things

4. My .NET is doing weird things...please help!

5. Doing strange things with text boxes

6. SQL Server doing wierd things...

7. Doing things with list boxes

8. Doing the ping thing

9. if you've done six impossible things before breakfast

10. SQL Server doing wierd things...

11. Crystal Smart Viewer doing odd things

12. ADO update doing strange things

 

 
Powered by phpBB® Forum Software