Trim string vII

  • Thread starter Thread starter Jesse Hamilton
  • Start date Start date
J

Jesse Hamilton

Ok, next question, how would you keep all the text starting from the right
up until you encounter a "\"?

Jesse
 
One way:


Sub getName()
Dim str As String
str = "C:\MyWebServer\MyFolder\MyPage.htm"

str = Left(str, Len(str) - 4)

Dim x As Integer
Dim lenStr As Long
Dim newString As String
lenStr = Len(str)

For x = lenStr To 0 Step -1
If Mid(str, x, 1) = "\" Then
x = 0
Else
newString = Mid(str, x, 1) & newString
End If
Next
Debug.Print newString


End Sub
 
If you use a function from Tom Ogilvy (working in 97-2003)

Function Split97(sStr As Variant, sdelim As String) As Variant
Split97 = Evaluate("{""" & _
Application.Substitute(sStr, sdelim, """,""") & """}")
End Function


Sub test2()
Dim fname As String
Dim sfname As String
Dim varr As Variant
fname = "C:\testfile.htm"
varr = Split97(fname, "\")
sfname = varr(UBound(varr))

MsgBox sfname

End Sub
 
Back
Top