I have say: C:\blah\foo\bar.txt I need just bar.txt... I see InStr returns first occurence..I probably need last occurence? Jon
Use InStrRev() to get last occurence of backslash and then Mid(... pos +1): VB Code: Private Sub Command1_Click() Dim sText$ sText = "C:\blah\foo\bar.txt" MsgBox Mid(sText, InStrRev(sText, "\") + 1) End Sub
Private Sub Command1_Click() Dim sText$ sText = "C:\blah\foo\bar.txt" MsgBox Mid(sText, InStrRev(sText, "\") + 1) End Sub
or... VB Code: Dim sText$ Dim strParts() As String sText = "C:\blah\foo\bar.txt" strParts = Split(sText, "\") MsgBox strParts(UBound(strParts))
Dim sText$ Dim strParts() As String sText = "C:\blah\foo\bar.txt" strParts = Split(sText, "\") MsgBox strParts(UBound(strParts))
Tips, Examples & Tutorials: A valuable forum tool • Generate unique TreeView keys • TreeView with "open" and "closed folder" icons • Time code using GetTickCount • How to trap the Tab key • Scroll a form • NumberBox ActiveX control • Color a ListView row • An InputBox form • How to use SaveSetting and GetSetting • A program registration scheme • Spellcheck a Textbox • Resize controls • Open Windows Explorer at Last Visited Path • A Blackjack Game • Count lines of code • Private Message Viewer • Copy/Paste VB Code • Paste VB Code Add-In • Insert Procedure Names Add-In • A calculator for the game of Spider • My review of REALbasic 2008 • VB6 Debug Tutorial • Picture/Video Viewer • VBF Photo Contest Winners 2009 - 2016
Forum Rules