这有点令人困惑,为什么会这样?
Console.WriteLine(IsNumeric("$0")) - False
Console.WriteLine(IsNumeric("€0")) - False
Console.WriteLine(IsNumeric("£0")) - True
Console.WriteLine(IsNumeric("£")) - False
对我来说似乎很奇怪,这是什么原因呢
编辑:也在最后工作:
Console.WriteLine(IsNumeric("300£")) - True
Console.WriteLine(IsNumeric("300£0")) - False
Console.WriteLine(IsNumeric("£300£")) - False
答案 0 :(得分:7)
住在意大利 - 在意大利语区域运行
Console.WriteLine(IsNumeric("$0")) ' False
Console.WriteLine(IsNumeric("€0")) ' True
Console.WriteLine(IsNumeric("£0")) ' False
Console.WriteLine(IsNumeric("£")) ' False
虽然这会让你永远回归
using System.Globalization;
Console.WriteLine(MyIsNumeric("$0", NumberStyles.AllowCurrencySymbol, "en-US"))
Console.WriteLine(MyIsNumeric("€0", NumberStyles.AllowCurrencySymbol, "it-IT"))
Console.WriteLine(MyIsNumeric("£0", NumberStyles.AllowCurrencySymbol, "en-GB"))
Public Function MyIsNumeric(ByVal val as String, ByVal NumberStyle as NumberStyles, cName as String) as Boolean
Dim result as Double
return Double.TryParse(val,NumberStyle, new CultureInfo(cName), result)
End Function
因此,我们可以得出结论,IsNumeric(最初在VB6运行时中定义)smart
足以在解析当前区域设置货币符号(如果它们位于输入字符串之前或之后)时排除。