Click here to Skip to main content
15,885,141 members
Articles / Programming Languages / C#
Alternative
Tip/Trick

Basic string to integer conversion extensions

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
15 Jun 2011CPOL 9.2K   1
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)


Written By
Student
Wales Wales
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralGood suggestion. Pin
leopard44716-Jun-11 18:41
leopard44716-Jun-11 18:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.