angelcake angelcake - 1 year ago 92 Question

VB.Net Reverser and Substring a string

I have multiple files with date and each file has different length of file name.
I would like to cut the string to only get the file name. The way I do it in Sql is REVERSE(SUBSTRING(REVERSE('the full file name'), 10, LEN('the full file name')))

Example File names:


And I want the result to be:


How do I accomplish it in VB.Net Code?

Answer Source

Something like this.

Dim s As String = "Myfile_20160708"
If s.Contains("_"c) Then
    s = s.Substring(0, s.IndexOf("_"c))
End If

uses Indexof to find the location of the underscore and substring to get the part you are interested in

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download