如何从字符串中删除$符号

如何从字符串中删除$符号

问题描述:

我想在货币格式的开头没有“$”格式化货币。

我该怎么做?我试过,但它不工作:

Format(e.Row.Cells(7).Text, "{0:n}") 

我知道$的1,234是:

Format(e.Row.Cells(7).Text, "Currency") 

但我试图删除

$

在货币前面。

+0

如果你不希望的货币,不使用货币格式。使用数字格式。 – GSerg

+0

VS中有一个设置,根据您想要显示的内容更改货币符号。如果你什么都不需要,那就用'Integer'或者'Decimal/Double' – MAC

+0

[格式化一个像货币但没有货币符号(C#)的双值的可能的重复](http://*.com/questions/1048643)/format-a-double-value-like-currency-but-without-the-currency-sign-c)http://*.com/a/1048669/1316573 –

Dim value As Double = e.Row.Cells(7).Text 
Dim val2 As String 
val2 = (value.ToString("#,#", CultureInfo.InvariantCulture)) 
e.Row.Cells(7).Text = String.Format(CultureInfo.InvariantCulture, "{0:#,#}", val2) 

不要忘了Imports System.Globalization

TrimStart()功能

Dim strVal As String = "$1,234" 
strVal = strVal.TrimStart("$") 

replace()功能

Dim strVal As String = "$1,234" 
strVal = strVal.Replace("$",String.Empty) 

你可以使用这样

e.Row.Cells(7).Text = e.Row.Cells(7).Text.TrimStart("$") 

e.Row.Cells(7).Text = e.Row.Cells(7).Text.Replace("$",String.Empty)