assign 10 rightmost characters of filename to string

chrishowell

New member
Joined
Jan 6, 2007
Messages
2
Programming Experience
3-5
i have been looking all over for this one for weeks. after pulling out my hair and having been sent to time-out many times by my wife, i finally give up.
so i'm hoping that someone here will have the answer!

i have a folder that contains file name such as below:
TEL1N1177673546.PDI
TEL6N1177701282.PDI
TEL48N1177794910.PDI, etc.

The filename is created from specific data:
TEL - stands for Telemetry and never changes
the next 1 or 2 digits stand for the channel (1 through 64) no leading zero.
we have no clue why the N is there other than to seperate the TEL and channel number from the last 10 digits, but it is always the 11th digit from the right.

the last ten digits are what i want to put in a string as they are UTC and i can convert it to mm/dd/yyyy hh:mm.

how can i get just the last 10 digits into a string?

thanks a lot in advance.
chris
 
Try this:
VB.NET:
        Dim TheStart As Integer = InStr(Me.txtInput.Text, "N")
        Dim TheEnd As Integer = InStr(Me.txtInput.Text, ".") - 1
        Dim TheLength As Integer = TheEnd - TheStart
        Me.txtOutput.Text = Me.txtInput.Text.Substring(TheStart, TheLength)
 
they worked!

:)those both worked like a charm. i had to play with integer to string, etc, but it does exactly what i was looking for.

i already see places where i could use one of the suggestions over the other one, so both are perfect!

thanks a lot!
chris
 
i already see places where i could use one of the suggestions over the other one, so both are perfect!

Avoid any suggestion that mentions the words "Microsoft.VisualBasic" or uses a legacy compatibility function like Left, Right, Mid, Instr (for a full list, press F2 and type Microsoft.VisualBasic; prefer using their newer counterparts in all cases)


Incidentally, a regular expression would have done nicely here too.. possibly a bit advanced right now, but just wait until you see them and are interested to know about them..

VB.NET:
        Dim r As New Regex("TEL(?<station>[0-9]+)N(?<utc>[0-9]{10}).PDI")
        Dim m As Match = r.Match("TEL1N1177673546.PDI")

        MessageBox.Show(m.Groups("station").Value) 'shows 1
        MessageBox.Show(m.Groups("utc").Value) 'shows 1177673546

Cool
 
Id do it more like this:

VB.NET:
       Dim test As String = "TEL48N1177794910.PDI"
TextBox1.Text = test.Substring(test.IndexOf("N") + 1, test.IndexOf(".") - (test.IndexOf("N") + 1))
you get back: 1177794910
 
VB.NET:
Dim search As String = IO.Path.GetFileNameWithoutExtension("TEL1N1177673546.PDI")
search = search.Substring(search.Length - 10)
 
VB.NET:
Dim search As String = IO.Path.GetFileNameWithoutExtension("TEL1N1177673546.PDI")
search = search.Substring(search.Length - 10)

Here's a one-line version:

IO.Path.GetFileNameWithoutExtension(fileName).Substring(fileName.Length - 14)

and another:

fileName.Replace("N", ".").Split("."c)(1)
 
Back
Top