Removing $ from string
-
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 ?
-
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 ?
digsy_ wrote:
I tried using LoanAmount.Replace("$", ""); but this doesnt work.
Well, how did you used it? Assuming
LoadAmount
is string, you must doLoadAmount = 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
-
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 ?
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[^]
-
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[^]
Would work fine if the amounts were all three digits. What happens with $50 or $4000?
only two letters away from being an asset
-
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[^]
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.
-
Would work fine if the amounts were all three digits. What happens with $50 or $4000?
only two letters away from being an asset
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[^]
-
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 ?
digsy_ wrote:
I tried using LoanAmount.Replace("$", ""); but this doesnt work.
This will work: string temp=LoanAmount.Replace("$", "");
-
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 ?