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 ConvertToDecima l(String str)
{
String pattern = @"^\(?-?[\d]*[,]*[\d]*\.?[\d]*\)?";
System.Text.Reg ularExpressions .Match match
=System.Text.Re gularExpression s.Regex.Match(s tr, pattern);
if (match.Success)
{
decimal result;
//try to parse to decimal normally
if (decimal.TryPar se(match.Groups[0].ToString(),
System.Globaliz ation.NumberSty les.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 ConvertToDecima l(String str)
{
String pattern = @"^\(?-?[\d]*[,]*[\d]*\.?[\d]*\)?";
System.Text.Reg ularExpressions .Match match
=System.Text.Re gularExpression s.Regex.Match(s tr, pattern);
if (match.Success)
{
decimal result;
//try to parse to decimal normally
if (decimal.TryPar se(match.Groups[0].ToString(),
System.Globaliz ation.NumberSty les.Any, null, out result))
return result;
}
return 0;
}--
Mike
Comment