Replacement for IsNumeric??

H

Howard Kaikow

Does VB .NET or the framework include a function/method that correctly
identifies the following as not being numeric?

3,6
3,,6

Assuming the decimal mark is Full Stop.

And, if the decimal mark is COMMA:

3.6 and 3..6 would be invalid
 
H

Herfried K. Wagner [MVP]

* "Howard Kaikow said:
Does VB .NET or the framework include a function/method that correctly
identifies the following as not being numeric?

Have a look at 'Double.TryParse'.
 
A

AirPete

Howard said:
Does VB .NET or the framework include a function/method that correctly
identifies the following as not being numeric?

3,6
3,,6

Assuming the decimal mark is Full Stop.

And, if the decimal mark is COMMA:

3.6 and 3..6 would be invalid

It's a little inefficent, but you could do something like:

public function isnumeric(str as string) as bool
try
decimal.parse(str)
return true
catch
return false
end try
end function


- Pete
 
A

AirPete

Herfried said:
Have a look at 'Double.TryParse'.

This is the better solution; exceptions are very inefficent. I looked for
Decimal.TryParse, but didn't find it :)

- Pete
 
H

Howard Kaikow

Alas, Parse has the same issue as IsNumeric, e.g., "100,14" gets converted
to 10014.
 

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