0

Hey Guys,

Any help on this would be greatly appreciated.

So I've got a list of strings in ListBox1 and I want to remove the last seven characters from each string in the list and write the output to an excel file...

Any tips would be greatly appreciated.

Thanks in advance

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by codeorder
0

Here is the code:

Dim result As String
result = beginingString.Text.Remove(beginingString.Text.Length - 7, 7)
0

Sorry mate, that reply didn't help too much at all (Beginning was spelt wrong and I don't even think that's a vb function anyway...)

I'm after code that will loop through each item in the listbox and remove the last 7 characters from each item and save the output to an excel file...

cheers guys :)

0
Dim tempList As New List(Of String) '// create temp list.
        For Each itm As String In ListBox1.Items '// loop thru listbox.
            If itm.Length > 7 Then '// to not get errors, check if item's length is greater than 7.
                tempList.Add(itm.Substring(0, 7)) '// if greater than 7, get the substring.
            Else
                tempList.Add(itm) '// if less than 7, add item as is.
            End If
        Next
        ListBox1.Items.Clear()
        ListBox1.DataSource = tempList '// add items back to the listbox.

Edited by codeorder: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.