Click here to Skip to main content
15,886,795 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have added selected items to the shopping cart in the
format of

image quantity(price)


in that i have to retrieve the quantity and price how to get it.
i am adding a listbox control i that i am adding item in above format

image quantity(price)
Posted
Updated 1-Jun-12 20:35pm
v2
Comments
The Doer 2-Jun-12 2:27am    
from where you want to retrieve data?? in which control??
[no name] 2-Jun-12 2:33am    
from list box control

Use string.LastIndexOf and string.IndexOf to get the two brackets.
You can then use string.SubString to get the values.
 
Share this answer
 
v2
I think you may be writing the value of quantity and value of price in the above format like image 45.5(35.45), in which case the following Regex pattern can be used to retrieve the quantity and price part.
C#
string qtyPrice = @"image  45.5(35.45) ";
    Match match = Regex.Match(qtyPrice,@"\s+([\d.]+)\s*\(\s*([\d.]+)\s*\)",
         RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
    double quantity;
    decimal price;
    if (match.Success){
        double.TryParse(match.Groups[1].Value,out quantity);
        decimal.TryParse(match.Groups[2].Value,out price);
    }

//quantity=45.5
//price=35.45

In the above code the pattern @"\s+([\d.]+)\s*\(\s*([\d.]+)\s*\) matches the value between space and ( into the Groups[1] and matches the value between ( and ) into Groups[2]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900