Extract amount with currency sign

Hi,

I am looking to extract a currency amount but without the currency before it. For example from the below i want the figures and not the currency sign how can i go about it?
£1100.01
$520.00
SGD 503.00

I have tried using trim but its not accurate, would i need regex coding?

can anybody help?

Filter your text with System.Text.RegularExpressions.Regex.Matches(MyText, "\d+(\.\d+)*"), where MyText is the text you’ve extracted. Then each match can be converted to a double if need be, but will only contain 1100.01, 520.00, and 503.00 as shown in your example above.

I am getting an error, says i can’t assign a generic value to an assign activity @Anthony_Humphries

That expression returns a String type. Make sure you’re using a String variable to assign it. It is generally unadvised to use the Generic type.

I seem to be getting more errors when changing the variable to string.
Let me add some more info may help clear things up a bit, right so am using get text to extract the figure, which when am storing the data its in a generic variable as its picking up the currency.
I then want to put the figure without the currency sign in an if statement to say ‘Amount > 500’ then do this else do this.
Because its picking up the currency everytime, the bot keeps going down the ‘else’ line

@Anthony_Humphries

When you extract text, it should be stored as a string. If you need it to be used as a value for comparison as in Amount > 500, if Amount is a string, you can use CDbl(Amount) > 500.

1 Like

Hello,

While Decimal type is slow I prefer it when dealing with money. Please adapt the following to suit your needs.

Assign (String)
pattern = (?<currency>\D+?)\s*(?<amount>[\d\.]+)

Assign (MatchCollection)
matches = System.Text.RegularExpressions.Regex.Matches(myText, pattern)

ForEach match in matches (with TypeArgument as Match)

  • Assign (Decimal)
    amount = Decimal.Parse(match.Groups("amount").Value)

  • Assign (String)
    currency = match.Groups("currency").Value

1 Like

this is the error i get when i change the variable to string @Anthony_Humphries

The System.Text.RegularExpressions…etc. should be assigned to a variable of type MatchCollection. You can the iterate over this collection to get the value of each match. If item is one of the items in the collection, you can get the string you want from item.Value.

1 Like