flat assembler
Message board for the users of flat assembler.

Index > Heap > [VB.NET] Trimming strings in a listbox?

Author
Thread Post new topic Reply to topic
DataHunter2009



Joined: 10 Jun 2005
Posts: 144
DataHunter2009
Hello! I'm working on (another) program called Snippet Manager. I have a listbox that lists each .snpt file in the snippets directory, but as you can see in the screenshot here, the listbox shows the directory and the extension. I only want it to show the filename without the extension.

Here's my code:

Code:
(IN FORM1 LOAD EVENT)
        If System.IO.Directory.Exists("snippets") = False Then
            MessageBox.Show("The snippets directory does not exist! It will be created for you...", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Else
            files = System.IO.Directory.GetFiles("snippets")
        End If
        ListBox1.Items.AddRange(files)    


I've tried the Trim function, but the whole array thing makes it confusing. The only possible way I saw how to do it was to make a for loop through each item and trim them one by one. I tried that aswell, but It didn't work (though I've never had much experience with loops or arrays).

Sad
Post 13 Aug 2005, 22:00
View user's profile Send private message Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
comrade
why didn't this work?
Code:
For Each file As String in Files
    ListBox1.Items.Add(Trim(file))
Next file
    
Post 14 Aug 2005, 01:18
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
DataHunter2009



Joined: 10 Jun 2005
Posts: 144
DataHunter2009
I have this now:

Code:
        For Each file As String In files
            file.TrimStart("s", "n", "i", "p", "e", "t", "s", "\")
            file.TrimEnd(".", "s", "n", "p", "t")
            ListBox1.Items.Add(file)
        Next file    


But the string doesn't get trimmed... It does when I do this however:

Code:
        For Each file As String In files
            ListBox1.Items.Add(file.TrimStart("s", "n", "i", "p", "e", "t", "s", "\"))
        Next file    


But then I don't know how to trim the end at the same time. Sad
Post 14 Aug 2005, 01:30
View user's profile Send private message Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
comrade
What do u mean by Trim? Trimming means removing excess whitespace from the beginning and end of a string.
Post 14 Aug 2005, 03:48
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
DataHunter2009



Joined: 10 Jun 2005
Posts: 144
DataHunter2009
Yeah, that's what the regular Trim() function does, but TrimStart removes an array of character from the beginning of a string. TrimEnd does the same thing, except the characters are removed from the end. I just don't know how to Trim the beginning AND the end...
Post 14 Aug 2005, 05:11
View user's profile Send private message Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
comrade
file.TrimStart(....).TrimEnd(...)
Post 14 Aug 2005, 15:40
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
DataHunter2009



Joined: 10 Jun 2005
Posts: 144
DataHunter2009
That works! Thanks. Once again... another problem however... when I add a snippet to the library, it trims off the "st" on the end of test. Any way to stop that?

NVM... i just made it when it doesn't use an extension at all. It all works fine now. Very Happy
Post 14 Aug 2005, 19:11
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.