CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #2
    Join Date
    Mar 2012
    Posts
    17

    Re: Trim ComboBox items

    Quote Originally Posted by osadalakimdi View Post
    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

    Code:
    String data = "Processor:12000";
    String result = data.substring(data.lastIndexOf(":")+1);
    we substring the String. String.substring([b[This is the Start Index[/b])
    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));
    }
    Last edited by Neolitz; March 17th, 2012 at 01:13 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured