Q:

Find and extract an amount from a string

I have to find an amount from a string.
string s = "I was paid $17,000 for the work.";

Code should extract $17,000. How can i do this?

A:

Try regular expressions:
string sentence = "I was paid $17,000 for the work.";
string amount = Regex.Match(sentence, @"\$\d+,\d+").Value;

I used pattern \$\d+,\d+ to match dollar sign, digits, comma, and again digits.
You could also use \$[^ ]+ which will match dollar sign and then one or more characters different from space, this solution is more general.

