Hi MAF:
using System;
using System.Text.RegularExpressions;
class MainApp
{
public static void Main()
{
string str1 = "DEADBEEF";
string strOct = String.Concat("[0-7]{", str1.Length, "}");
bool RetBoolOct = Regex.IsMatch(str1, strOct);
Console.WriteLine(RetBoolOct);
string strHex = String.Concat("[0-9A-Fa-f]{", str1.Length, "}");
bool RetBoolHex = Regex.IsMatch(str1, strHex);
Console.WriteLine(RetBoolHex);
}
}
"Joshua Flanagan" wrote:
The simplest way to test would probably be with a regular expression.
using System.Text.RegularExpressions;
....
// to detect an oct number
Regex.IsMatch(givenString, "[0-7]+");
// to detect a hex number
Regex.IsMatch(givenString, "[0-9A-Fa-f]+");
You can also use Int32.Parse() or Decimal.Parse() to convert a hex
number to a decimal integer.
Joshua Flanagan
http://flimflan.com/blog
MAF wrote: How can I test a given string to see if the string is a hex number or an oct
number?