Remove $ from string

Posted on 2009-04-23
Last Modified: 2012-05-06
if I have a value like this $2.95 or $100, i want to remove $.
I can use Replace("$","") but i might have other currency symbols.

How can I remvoe symbols but leave digits and decima? (want 2.95)
Question by:Camillia
    LVL 14

    Expert Comment


    You can use like

    System.Globalization.NumberFormatInfo nfi = new System.Globalization.NumberFormatInfo();
    nfi.CurrencySymbol = "$";
    nfi.CurrencyDecimalSeparator = ".";
    nfi.NumberGroupSeparator = ",";
    nfi.NumberDecimalDigits = 2;

    double currencyvalue =  Decimal.Parse("$96,000.00",nfi);
    LVL 7

    Author Comment

    well, if I somethng else besides $, then i have to keep hardcoding symbols??
    LVL 14

    Expert Comment

    The currency will be based on the culture. I have created NumberFormatInfo for US. So if you have track of the culture then you can get the NumberFormatInfo from the CultureInfo class and use it directly.
    LVL 74

    Accepted Solution

    Just curious, but couldn't you just substring everything after the first character?

    string value = "$2.95"

    value = value.Substring(1)
    LVL 7

    Author Comment

    yes, i didnt think about substring. let me try that

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now