string manipulation using items in listbox

tergerregret

New member
Joined
Feb 21, 2006
Messages
3
Programming Experience
3-5
hi peeps,
i am a new member here, but really would like to discuss wif all of you, after seeing how active all the conversation has been..
my question would be,
is there anyone can give me examples on how to do string manipulation(get string length, replace characters, remove characters, get string location..so on), using items in listbox (lstBox1). one example i could find is on how to add data,
lstBox1.items.add(...
but how about other manipulation? is there any solution/example?
help..
 
I'm not sure i understand exactly what you mean. A listbox's collection is always an 'Object Collection' so therefore it can hold anything. If you have a collection of strings in your listbox then you can perfom any kind of manipulation you have mentioned and more besides. You can do this by declaring a string object (though that statement isn't 100% correct) and assigning it to one the string objects in your listbox. Is this what you are after?
 
Do you want to keep the listbox items as they are or update them after manipulation?
String manipulation is explained in this forum all over the place, just refine your search a little.
VB.NET:
        For i As Integer = 0 To ListBox1.Items.Count - 1
            tempstring = ListBox1.Items(i)
            'do string manipulation on "tempstring" here
        Next i
Looping through a listbox's items and assigning it to a string then doing something to that string.

or you could create one big string of the listbox's items with the loop above just change the line to:
tempstring += ListBox1.Items(i)
and then manipulate "tempstring" elsewhere.

Narrow your question down a bit and get more specific, one or two problems at a time. If you structure your question correctly the answers will be more valuable to you.

Welcome to the forum,
 
thanks for the responds, and sorry for the statement i gave earlier..

what i actually mean is that, i need a sample on how to remove,replace,and do other string manipulation towards the collection of string in listbox.

for example, if i used textbox, and need to remove a string, i will used:
textbox1.text = string_1
textbox2.text = string_1.remove(x,y)
so, how do i do the same function in listbox? i understand that it had something to do with looping (for loop etc), but i still could not find one solid example that can lead me in my coding.so can anyone help me?
 
Not sure what you are really asking. :confused:
Nevertheless, an attempt at an answer:
VB.NET:
[COLOR=#008000]' Remove some characters in first string item[/COLOR]
ListBoxStrings.Items(0) = ListBoxStrings.Items(0).ToString.Remove(x, y)
[COLOR=#008000]' Remove second item altogether[/COLOR]
ListBoxStrings.Items.RemoveAt(1)
 
Instead of textbox.text you will use:
VB.NET:
tempstring = ListBox1.SelectedItem
If you want the selected item.

Now for the second listbox - more information is needed for specific code examples.
A listbox item is a string - so manipulate 'tempstring and either add it or update it to the second listbox. Adding to a listbox is different than updating existing values...
 
Leading on from what DaveT MackTool has said, If you have option strict and option explicit on then you will need to convert the listbox.selecteditem to a string object...

VB.NET:
Convert.Tostring(listbox.selecteditem)
 
Back
Top