[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 308
  • Last Modified:

Remove $ from string

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)
0
Camillia
Asked:
Camillia
  • 2
  • 2
1 Solution
 
GiftsonDJohnCommented:
Hi,

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);
0
 
CamilliaAuthor Commented:
well, if I somethng else besides $, then i have to keep hardcoding symbols??
0
 
GiftsonDJohnCommented:
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.
0
 
käµfm³d 👽Commented:
Just curious, but couldn't you just substring everything after the first character?

string value = "$2.95"

value = value.Substring(1)
0
 
CamilliaAuthor Commented:
yes, i didnt think about substring. let me try that
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now