ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Trim string vII (https://www.excelbanter.com/excel-programming/282096-trim-string-vii.html)

Jesse Hamilton[_2_]

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

Jesse



Michael Hopwood

Trim string vII
 
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

--
Michael Hopwood (Phobos)


"Jesse Hamilton" wrote in message
news:BxSrb.16169$jy.13609@clgrps13...
Ok, next question, how would you keep all the text starting from the right
up until you encounter a "\"?

Jesse





Ron de Bruin

Trim string vII
 
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


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Jesse Hamilton" wrote in message news:BxSrb.16169$jy.13609@clgrps13...
Ok, next question, how would you keep all the text starting from the right
up until you encounter a "\"?

Jesse






All times are GMT +1. The time now is 09:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com