Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I'm looking to find out how I can tell if a filename contains two or more dots

eg. 45FGG.TESTDOC.MAY12.zip

I want to end up splitting the filename into two parts

45FGG.TESTDOC.MAY12

.zip

I can do it for one dot using LastIndexOf, but more than two dots I'm stuck

Thanks
J
Posted

How about this:
VB
Dim s as sting= "45FGG.TESTDOC.MAY12.zip"
Dim result() as string
result = s.Split(".")


result.count-2 should the give you the number of . in the text :)
 
Share this answer
 
v2
VB
Dim strFileName As String = "45FGG.TESTDOC.MAY12.zip"

VB
Dim FileNameArray() As String = strFileName.Split(".") "

VB
Dim ArrayLength As Integer = FileNameArray.Length
Dim FileNameExtension As String = FileNameArray(ArrayLength -1) '.zip 
Dim FileNameExtensionLength As Integer =  FileNameExtension.Length
Dim FileNameLength As Integer = strFileName.Length - FileNameExtensionLength
Dim FileName As String = Strings.Left(strFileName, FileNameLength) '45FGG.TESTDOC.MAY12
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900