G
Guest
Hello,
I need a regular expression to match a currency with its symbol, for example
Pound66.99 must return 66.99 or Pound(66.99) or Pound-66.99 or -66.99Pound
return -66.99 or any other combination return the decimal number.
I have created a regular expression, but it seems that it does not work if
the number is Pound66.99 but it works if the sign is after the number:
public static Decimal ConvertToDecimal(String str)
{
String pattern = @"^\(?-?[\d]*[,]*[\d]*\.?[\d]*\)?";
System.Text.RegularExpressions.Match match
=System.Text.RegularExpressions.Regex.Match(str, pattern);
if (match.Success)
{
decimal result;
//try to parse to decimal normally
if (decimal.TryParse(match.Groups[0].ToString(),
System.Globalization.NumberStyles.Any, null, out result))
return result;
}
return 0;
}--
Mike
I need a regular expression to match a currency with its symbol, for example
Pound66.99 must return 66.99 or Pound(66.99) or Pound-66.99 or -66.99Pound
return -66.99 or any other combination return the decimal number.
I have created a regular expression, but it seems that it does not work if
the number is Pound66.99 but it works if the sign is after the number:
public static Decimal ConvertToDecimal(String str)
{
String pattern = @"^\(?-?[\d]*[,]*[\d]*\.?[\d]*\)?";
System.Text.RegularExpressions.Match match
=System.Text.RegularExpressions.Regex.Match(str, pattern);
if (match.Success)
{
decimal result;
//try to parse to decimal normally
if (decimal.TryParse(match.Groups[0].ToString(),
System.Globalization.NumberStyles.Any, null, out result))
return result;
}
return 0;
}--
Mike