Determining the type of a String

T

TGF

Hello,

I have a String input from a TextBox class. What I want to do it to
tell what type of number it is.. sometimes the user can enter a number like
'0xA5A2' or 'A5A2' (both considered hexadecimal), or they can enter '431345'
which is just an integer. These values are just examples, but i need to
know if one is hexadecimal and the other is integer. What methods of the
String class can do this?

-TGF
 
N

Nobody

So in the case of '1000', is that hexadecimal or decimal? '1000' is a valid
(and common) hexadecimal number, it is 4096 base 10. That is the reason for
0x, to distinguish it as hexadecimal. In any case, refer to Int32.Parse and
friends in MSDN.
 
T

Tom Clement

Also consider Decimal.TryParse() so you don't deal with exceptions.
Tom Clement
Apptero, Inc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top