Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Remove currency symbol and comma from number using Regex in C#

I am using following code to remove currency symbol and comma from number. This is deceimal number so . is expected

private string CleanCurrencyAmount(string no)
    {
        no = "£67609.787";
        string returnVal = string.Empty;

        string rgxPattern = @"(\p{Sc})?"; // this doesn't remove comma 

        Regex rgx = new Regex(rgxPattern);

        string x = rgx.Replace(no, "");

        string clean = Regex.Replace(no, "[^A-Za-z0-9 ]", "");  // this remove . too

        return returnVal;
    }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You’re close. Change to a character class with comma:

@"[\p{Sc},]"

Then replace with an empty string.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading