TrimEnd not working?

bjwade62

Centurion
Joined
Oct 31, 2003
Messages
104
Here's what I have. The selected text in a FileListBox is Detail.wmf. I'm trying to get strTrimmed to equal Detail without the .wmf. The trim never happens. No errors.... What am I doing wrong?

Visual Basic:
        Dim strTrimmed As String = Me.FileListBox.Text.TrimEnd(".wmf")

thanks,
Bernie
 
http://msdn2.microsoft.com/en-us/library/system.string.trimend.aspx would be worth a read as it explains what .TrimEnd does. If you want to remove the .wmf from the string you could either use something like

Visual Basic:
 Dim strTrimmed As String = Me.FileListBox.Text.Substring(0, s.Length - 4)

or even better use the Path class to do the work for you.
Visual Basic:
Dim strTrimmed As String = System.IO.Path.GetFileNameWithoutExtension(Me.FileListBox.Text)
 
I really like example #2. Thanks. Works great!

PlausiblyDamp said:
http://msdn2.microsoft.com/en-us/library/system.string.trimend.aspx would be worth a read as it explains what .TrimEnd does. If you want to remove the .wmf from the string you could either use something like

Visual Basic:
 Dim strTrimmed As String = Me.FileListBox.Text.Substring(0, s.Length - 4)

or even better use the Path class to do the work for you.
Visual Basic:
Dim strTrimmed As String = System.IO.Path.GetFileNameWithoutExtension(Me.FileListBox.Text)
 
Back
Top