Cropping a String

A

Andrew

I am looking to crop a String based on a "/". I want to crop out everything to the right of the "/" as well as the " " that is to the left of it. I ultimately want only that which is to left of " /".

As always your help is greatly appriciated.

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 
G

Greg Maxey

Not sure I copy what it is that you are seeking (you want to crop out
everything to the right of ... as well as everything to the left of).
Whouldn't that leave you with /?

Do you mean you want to keep everything to the left? If so, perhaps:

Sub Scratchmacro()
Dim pStr As String
Dim i As Long
pStr = "Day 7 of a / new dark age"
MsgBox Left(pStr, InStr(pStr, "/"))
End Sub
 
A

Andrew V

myStr = "before / after"
'value of myStr is "before / after"

myStr = Split(myStr," /")(0)
'value of myStr is "before"

Andrew V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top