Code archives/Algorithms/VB InstrRev() command

This code has been declared by its author to be Public Domain code.

Download source code

VB InstrRev() command by Jim Teeuwen2002
This one works just like the Instr() command, but it starts the search for the substring at the end of the sourcestring in stead of the front.

Handy for cutting off the filename from a complete systempath.
;// Usage: InStrRev(String$, Substring$[, Start%])

;// String: The source in wich to look
;// Substring: The string for wich to look
;// Start(optional): The numeric position, counted from the left,
;// which defines where to start the search for the substring. 

;// ### EXAMPLE ##################################
mystring$=InstrRev("c:\blitz3D\blitz3d.exe","\",1)
print "The filename is: "+mystring$

;// output
The filename is: blitz3d.exe

;// ### THE GOODS ################################

Function InstrRev$(sT$,sS$,index=0)
	While (Instr(sT$,sS$)>0)
		If Instr(sT$,sS$)>0 Then
			sT$=Mid$(sT$,Instr(sT$,sS$)+1)
		EndIf
	Wend
	If index=0 Then sT$=sS$+sT$
	Return sT$
End Function

Comments

None.

Code Archives Forum