Link to home
Start Free TrialLog in
Avatar of skij
skijFlag for Canada

asked on

ASP.NET/C#: Parse String, Get Three Numbers

Using ASP.NET/C#, I would like to parse this:
Round 1 ($12,34|$56.78|$98.76)

So that:
double a = 12.34;
double b = 56.78;
double c = 98.76;

But if the string is like this:
Round 1 ($12,34|$98.76)
double a = 12.34;
double b = 0;
double c = 98.76;
SOLUTION
Avatar of Dmitry G
Dmitry G
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
** No Points **

If I were a betting man, then I'd say you're probably not going to be dealing with "Round 1" every single time. If such be the case, then you can abstract the 1 away be turning it into a digit search (\d+) in ryancys' suggestion:

String p1 = @"Round \d+ \(\$(?<v1>[^|]+)\|\$(?<v2>[^|]+)\|\$(?<v3>[^|]+)\)";

Open in new window