65.9K
CodeProject is changing. Read more.
Home

Basic string to integer conversion extensions

starIconstarIconstarIconstarIconstarIcon

5.00/5 (2 votes)

Jun 15, 2011

CPOL
viewsIcon

9446

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:

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