Checking if string

G

Guest

Hi, I'm wondering how you can check a string that supposed to represent a
numeric value.

e.g. in old VB6 there was a method IsNumeric().

Is there an equivelant in C#?

Many thanks for your answers in advance
Ant
 
J

Jon Skeet [C# MVP]

Ant said:
Hi, I'm wondering how you can check a string that supposed to represent a
numeric value.

e.g. in old VB6 there was a method IsNumeric().

Is there an equivelant in C#?

Not really - you basically have to try to parse the string as a number
(eg using Double.TryParse).

If you really want to, you can add a reference to the
Microsoft.VisualBasic assembly, and use
Microsoft.VisualBasic.Information.IsNumeric().
 
M

Mark White

try
{
int iValue = int.Parse(mystring);
}
catch(FormatException fe)
{
Console.WriteLine(mystring + " is not numeric");
}
 

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