Determining the type of a String

  • Thread starter Thread starter TGF
  • Start date Start date
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
 
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.
 
Also consider Decimal.TryParse() so you don't deal with exceptions.
Tom Clement
Apptero, Inc.
 
Back
Top