I want to trim all ComboBox items for example:
ComboBox items
Processor:12000
Ram:5000
I want to trim string before colon (including 'colon') and send to listbox, so i can calculate all prices for items.
So plz tell me how can i do that.
Thanks
Printable View
I want to trim all ComboBox items for example:
ComboBox items
Processor:12000
Ram:5000
I want to trim string before colon (including 'colon') and send to listbox, so i can calculate all prices for items.
So plz tell me how can i do that.
Thanks
use this
we substring the String. String.substring([b[This is the Start Index[/b])Code:
String data = "Processor:12000";
String result = data.substring(data.lastIndexOf(":")+1);
so data.lastIndexOf(":") -> return the index of last : found in the string..
and return ":12000" but we need only "12000" so +1 for the index
update:
sorry i dont see that you want to calculate. so
try this code instead
Code:int total=0;
foreach (String text in [your list].Items) {
total+= int32.Parse(text.Substring(text.LastIndexOf(":")+1));
}
ThankYou so much Neolitz, Your code works
I use this:
string substring;
comboBox1.Items.ToString();
foreach(string s in comboBox1.Items)
{
substring = s.Substring(s.LastIndexOf(":") + 1);
listBox1.Items.Add(substring);
}
so now my problem is when i hit ">" button for add only selected item, all items of combobox trim and tranfer to listbox.
this code works for all item button(>>) button but not for selected item(">")
please help me.
the foreach will work with >>
now for the > try to do this
instead of do it to all data in the combo box we will do to the item selected and insert it to the list
your mistake is you use "foreach" which means do to all data in combo box, when you only wanted 1 item to added when > pressed.Code:String temp = comboBox1.Text;
temp = temp.Substring(temp .LastIndexOf(":") + 1);
listBox1.Items.add(temp);
so for >> keep using the old one
and for > use the new one
Hope this helps
Yeeah!! ThankYou so much.