[bb] VB InstrRev() command by Jim Teeuwen [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:43

Previous topic - Next topic

BlitzBot

Title : VB InstrRev() command
Author : Jim Teeuwen
Posted : 1+ years ago

Description : 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.


Code :
Code (blitzbasic) Select
;// 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:litz3Dlitz3d.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...