Keith,
In addition to the other comments:
Is there only one "_"?
Is there only one "."?
Do you want the first "_" or the last "_" before the "."?
Do you want the first "." or the last "." after the "_"?
I would use something like:
Private Shared Function GetStuff(ByVal name As String) As String
Dim index As Integer
index = name.LastIndexO f("_"c)
If index <> -1 Then
name = name.Substring( index + 1)
End If
index = name.IndexOf(". "c)
If index <> -1 Then
name = name.Substring( 0, index)
End If
Return name
End Function
Public Shared Sub Main()
Const Example1 As String = "mil2345_23.lst "
Const Example2 As String = "mil23456_1.lst "
Const Example3 As String = "mil5567_1234.l st"
Const Example4 As String = "mil55671234lst "
Const Example5 As String = "mil55671234.ls t"
Debug.WriteLine (GetStuff(Examp le1), Example1)
Debug.WriteLine (GetStuff(Examp le2), Example2)
Debug.WriteLine (GetStuff(Examp le3), Example3)
Debug.WriteLine (GetStuff(Examp le4), Example4)
Debug.WriteLine (GetStuff(Examp le5), Example5)
Return
End Sub
You can change the LastIndexOf & IndexOf of as appropriate. The "_"c is a
Char literal, as opposed to "_" which is a String literal.
Also normally I use the functions in System.IO.Path to remove parts of a
path, however I didn't here as you wanted a subpart of the file name...
Hope this helps
Jay
"Keith Kowalski" <ke***@rdfs.com > wrote in message
news:eb******** ******@TK2MSFTN GP11.phx.gbl...
I am passing in a string of varied length
Example1: mil2345_23.lst
Example2: mil23456_1.lst
Example3: mil5567_1234.ls t
What I need is to parse out all text after the _ (underscore) and before
the .)
From example 1 I need "23" returned
From example2 I need "1" Returned
From Example3 I need "12345" returned
I was think that MID$ would work but I am not sure how to do this.
Thanks in advance for all your help