isnumeric en c# .NET

mai 16, 2010

3 façons propres de tester si une chaine de caractères est numérique :

1ère méthode

Int32.TryParse(VARIABLE_A_TESTER);

2ème méthode

Une petite regex pour les courageux :

Using System.Text.RegularExpressions

System.Text.RegularExpressions.Regex.IsMatch(VARIABLE_A_TESTER,@ »(^[-+]?\d+(,?\d*)*\.?\d*([Ee][-+]\d*)?$)|(^[-+]?\d?(,?\d*)*\.\d+([Ee][-+]\d*)?$) »);

3ème méthode

Dans la librairie Microsoft.VisualBasic.dll

Microsoft.VisualBasic.Information.IsNumeric(VARIABLE_A_TESTER);

Plus d’information sur http://msdn.microsoft.com/fr-fr/library/microsoft.visualbasic.information.isnumeric.aspx

Tags: ,

Leave a Reply