Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Basic string to integer conversion extensions

5.00/5 (2 votes)
15 Jun 2011CPOL 9.4K  
As it stands, the TryParse method will fail if the string contains commas. E.g., 10,000. To get around this, you can use:bool isnumber=int.TryParse(text,System.Globalization.NumberStyles.Integer | System.Globalization.NumberStyles.AllowThousands, ...

As it stands, the TryParse method will fail if the string contains commas. E.g., 10,000. To get around this, you can use:


C#
bool isnumber=int.TryParse(text,System.Globalization.NumberStyles.Integer |
     System.Globalization.NumberStyles.AllowThousands,
     System.Globalization.CultureInfo.CurrentCulture, out n);

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)