Click here to Skip to main content
15,907,149 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi guys I am trying to select an integer after a cetain charachter from a string. This is for selecting the price of an item after the $ sign. for example Cheese Burger $5.00. Is there any way I could get the 5.00 from that string without hard coding it. Thanks alot for your help
Posted
Comments
karthik Udhayakumar 29-May-14 18:39pm    
post your code:(

1 solution

Not with StringBuilder.
However, it's easy with a string.
You can use:
C#
string input = "Cheese Burger $5.00 plus fries";
Regex pricePattern = new Regex(@"\$(\d+\.\d\d));
var match = pricePattern.Match(input);
decimal price = 0;
if (match.Success)
{
  price = decimal.Parse(match.Value);
}
 
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