Re: Can this be written better?
- From: "Mike Williams" <mike@xxxxxxxxxxxxxxxxx>
- Date: Sat, 31 Mar 2007 12:41:01 +0100
"Mike Williams" <mikea@xxxxxxxxxxxxxxxxx> wrote in message
news:%23SrcG13cHHA.4720@xxxxxxxxxxxxxxxxxxxxxxx
Actually, having given it a little more thought, it appears that the space
character (which my posted code properly accounts for) is the only
character, apart from the dot itself, which is permitted in a file name but
not permitted in a file extension. So, my previously posted code to strip
off a file extension is fine as it stands. It does not check the filename
itself for validity because it assumes the string you are passing to it is
the name of a file that actually exists on your disk. I'm sure there will be
snags with it that I haven't thought of, and Rick will probably turn it into
one of his famous "one liners", but here it is again, this time presented as
a function:
Mike
Private Function stripExtension(s1 As String) As String
Dim p1 As Long, p2 As Long
p1 = InStrRev(s1, ".")
p2 = InStrRev(s1, Space$(1))
If p1 > 0 And p2 < p1 Then
s1 = Left$(s1, p1 - 1)
End If
stripExtension = s1
End Function
.
- Follow-Ups:
- Re: Can this be written better?
- From: Rick Rothstein \(MVP - VB\)
- Re: Can this be written better?
- References:
- Re: Can this be written better?
- From: Mike Williams
- Re: Can this be written better?
- Prev by Date: Re: International MsgBox button captions
- Next by Date: Re: International MsgBox button captions
- Previous by thread: Re: Can this be written better?
- Next by thread: Re: Can this be written better?
- Index(es):
Relevant Pages
|