- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a couple of fairly fundamental VB.NET questions that I'm hoping some of you with a long history of VB.NET (not necessarily VBA) coding background can answer.
What is the difference between the InStr() function and the InStrRev() function in VB.NET?
I have read Microsoft's page for both, and it says they are supposed to function differently from each other, in fact opposite/reverse from each other, but they don't seem to work that way. They both seem do the same exact thing, the same exact way.
It says the InStr() function searches the source input string from left/start to right/end, looking for the target input String, then returns an Integer, which represents the position of where that target String is found within the source String, by counting the characters from the left/start of the source String to where it finds the target String.
This works exactly as it is described.
And it says the InStrRev() function is supposed to search through the source String to find the target String, but in the opposite direction (or reverse, hence the "Rev" in InStrRev). It is supposed to start searching and counting the characters from the right/end of the source String, towards the left/end of the source String, until it finds the target String, then return that count as the Integer.
This does not work as described.
Why?
Is this a glitch or error in iLogic, or in Inventor?
Has anyone tried using these outside of Inventor? If so, do they act differently there?
What's the use of one searching from left to right and the other searching from right to left if they both return the same Integer, when the target is obviously not in the same position from either end of the String?
If this is not an error or glitch, then is there another different function built into VB.NET that works the way InStrRev's description sounds like it should work?
Is sure seems like VB.NET should have implemented a function that works the way I'm wanting by now.
Within this iLogic rule:
Dim oSource As String = "ABCDEFGH"
Dim oTarget As String = "G"
MsgBox("InStr(oSource, oTarget) = " & InStr(oSource, oTarget) & vbCrLf & _
"InStrRev(oSource, oTarget) = " & InStrRev(oSource, oTarget))
both functions return 7.
But it seems to me that the InStrRev() function should be returning 2, instead of 7, if it were counding from the right/end. I want a function that finds the position of the oTarget ("G") within the oSource ("ABCDEFGH"), starting from the right/end, and counting how many characters the oTarget is from that right/end.
This functionality I seek sure seems like an extremely useful tool for an extremely common data type (String) that should have been implemented by now.
I've tried every setting of every option that both of these functions have, but they don't change how they work.
Any explanations, alternate functions, or suggestions welcome.
Wesley Crihfield
(Not an Autodesk Employee)
Solved! Go to Solution.