Does VB.net IsNumeric Treat £ as Numeric?

This is a bit confusing, why so?

Console.WriteLine(IsNumeric("$0")) - False Console.WriteLine(IsNumeric("€0")) - False Console.WriteLine(IsNumeric("£0")) - True Console.WriteLine(IsNumeric("£")) - False 

It seems strange to me what reason he does it

Edit: works and at the end:

 Console.WriteLine(IsNumeric("300£")) - True Console.WriteLine(IsNumeric("300£0")) - False Console.WriteLine(IsNumeric("£300£")) - False 
+4
source share
1 answer

Living in Italy - work in Italian

 Console.WriteLine(IsNumeric("$0")) ' False Console.WriteLine(IsNumeric("€0")) ' True Console.WriteLine(IsNumeric("£0")) ' False Console.WriteLine(IsNumeric("£")) ' False 

until it always returns true

 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 

So, we can conclude that IsNumeric (originally defined in the VB6 runtime) is smart enough to exclude the current locale currency symbols from its parsing if they precede or follow the input string.

+7
source

Source: https://habr.com/ru/post/1443518/


All Articles