Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Removing $ from string

Removing $ from string

Scheduled Pinned Locked Moved C#
question
8 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    digsy_
    wrote on last edited by
    #1

    I have currency values in a dropdownlist that are formatting to look like $50, $100 etc using {0:C0} I need to remove the $ symbol before converting the string to an Int32 I tried using LoanAmount.Replace("$", ""); but this doesnt work. What should I be doing ?

    D T G S 4 Replies Last reply
    0
    • D digsy_

      I have currency values in a dropdownlist that are formatting to look like $50, $100 etc using {0:C0} I need to remove the $ symbol before converting the string to an Int32 I tried using LoanAmount.Replace("$", ""); but this doesnt work. What should I be doing ?

      D Offline
      D Offline
      DavidNohejl
      wrote on last edited by
      #2

      digsy_ wrote:

      I tried using LoanAmount.Replace("$", ""); but this doesnt work.

      Well, how did you used it? Assuming LoadAmount is string, you must do LoadAmount = LoadAmount.Replace("$", "") or use another string variable because strings are immutable types, original string CANNOT change.


      "Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe

      1 Reply Last reply
      0
      • D digsy_

        I have currency values in a dropdownlist that are formatting to look like $50, $100 etc using {0:C0} I need to remove the $ symbol before converting the string to an Int32 I tried using LoanAmount.Replace("$", ""); but this doesnt work. What should I be doing ?

        T Offline
        T Offline
        Thomas Stockwell
        wrote on last edited by
        #3

        string s="$400"; s=s.substring(1,3); int amnt=Convert.toInt32(s);

        Regards, Thomas Stockwell Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Visit my homepage Oracle Studios[^]

        N S 2 Replies Last reply
        0
        • T Thomas Stockwell

          string s="$400"; s=s.substring(1,3); int amnt=Convert.toInt32(s);

          Regards, Thomas Stockwell Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Visit my homepage Oracle Studios[^]

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          Would work fine if the amounts were all three digits. What happens with $50 or $4000?


          only two letters away from being an asset

          T 1 Reply Last reply
          0
          • T Thomas Stockwell

            string s="$400"; s=s.substring(1,3); int amnt=Convert.toInt32(s);

            Regards, Thomas Stockwell Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Visit my homepage Oracle Studios[^]

            S Offline
            S Offline
            ScottM1
            wrote on last edited by
            #5

            Thomas Stockwell wrote:

            string s="$400"; s=s.substring(1,3); int amnt=Convert.toInt32(s);

            What if it's $4000

            s=s.substring(1,s.Length);
            int amnt=Convert.toInt32(s);

            :)

            There are 10 types of people in the world, those who understand binary and those who dont.

            1 Reply Last reply
            0
            • N Not Active

              Would work fine if the amounts were all three digits. What happens with $50 or $4000?


              only two letters away from being an asset

              T Offline
              T Offline
              Thomas Stockwell
              wrote on last edited by
              #6

              I was merely explaining the principle, the code can be modified to handle the full length of the string.

              Regards, Thomas Stockwell Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Visit my homepage Oracle Studios[^]

              1 Reply Last reply
              0
              • D digsy_

                I have currency values in a dropdownlist that are formatting to look like $50, $100 etc using {0:C0} I need to remove the $ symbol before converting the string to an Int32 I tried using LoanAmount.Replace("$", ""); but this doesnt work. What should I be doing ?

                G Offline
                G Offline
                Giorgi Dalakishvili
                wrote on last edited by
                #7

                digsy_ wrote:

                I tried using LoanAmount.Replace("$", ""); but this doesnt work.

                This will work: string temp=LoanAmount.Replace("$", "");

                my articles

                1 Reply Last reply
                0
                • D digsy_

                  I have currency values in a dropdownlist that are formatting to look like $50, $100 etc using {0:C0} I need to remove the $ symbol before converting the string to an Int32 I tried using LoanAmount.Replace("$", ""); but this doesnt work. What should I be doing ?

                  S Offline
                  S Offline
                  Scott Dorman
                  wrote on last edited by
                  #8

                  Assuming you are using .NET Framework v2.0 or later, you can use the Int32.TryParse(String, NumberStyles, IFormatProvider, Int32) method[^]. For the NumberStyles parameter, you probably want to use NumberStyles.Currency.

                  ----------------------------- In just two days, tomorrow will be yesterday.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups