生活在意大利 - 在意大利地区运行
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
足以从其解析中排除当前区域设置货币符号(如果它们位于输入字符串之前或之后)。