Extracting $ Amount in a String


I have a string comes in different format and how to extract first $Amount from the String ,
example of string are
$3 SV CHG-WV PPA/NC --> for this expected $3
$4SC,$20NSF$7MAX$1MIN --> for this expected $4
$0SC,$20NSF$7MAX$1MIN --> for this expected 0 .50 EFT NSA Srv Chg --> for this expected $.50
MD $4 SRVCHG-$20 NSF --> for this expected 4 MD .95 SRVCHG/20 NSF --> for this expected .95
PLAB-DI AZ $4 SC --> for this expected $4



The easiest way is to use Regular Expressions.
The pattern would be : $\d*.?\d*

You could use Assign activity that way

amount = New System.Text.RegularExpressions.Regex("$\d*.?\d*").match(line).ToString

It would catch only the first occurrence in the string you pass.



I’m not exactly sure but optional decimal = \.?*. Your regex is missing a backslash,if results are fine please ignore this.



Yes you are right, i forgot to escape the ‘.’, and we can assume that the decimals will be only two digits.

He should rather use yours.Somehow both of them work for type of inputs :slight_smile: but he should rather use yours.


Thank you @vvaidya it worked for all the scenario “$\d*.?\d{1,2}” , great thought

Thanks @Florent_Salendres used your for OneLiner to get the value first occurrence of

Used New System.Text.RegularExpressions.Regex("$\d*.?\d{1,2}").Match(strDropDownValue).ToString
Thank you both for your quick response and saving my day, :slight_smile: