473,406 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

IsNumeric C# equivalent

IS there a C# equivalent to the VB IsNumeric function?

Nov 17 '05 #1
7 8322
Check Parse and TryParse methods for corresponding types, Int, Long etc.

HTH
Alex

"Stephan Bour" <sb***@niaid.nih.gov> wrote in message
news:BBCE9144.B64C%sb***@niaid.nih.gov...
IS there a C# equivalent to the VB IsNumeric function?

Nov 17 '05 #2
Try the static IsNumber() method on the Char class.

E.g.:

char c = 'a';
if (Char.IsNumber(c))
{
//do whatever...
}

Hope that helps.

Cheers,
Wim Hollebrandse
http://www.wimdows.net
http://www.wimdows.com

---
Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/
Nov 17 '05 #3
Actually, IsNumeric does two things: converts a string and returns a boolean
true if the resulting expression is recognized as a number. Parse only
converts a string representation of a number to double. I need the boolean
return to validate a text box entry that can't be easily checked with a
validator.
Stephan.

in article eu**************@tk2msftngp13.phx.gbl, AlexS at
sa***********@SPAMsympaticoPLEASE.ca wrote on 11/5/03 14:39:
Check Parse and TryParse methods for corresponding types, Int, Long etc.

HTH
Alex

"Stephan Bour" <sb***@niaid.nih.gov> wrote in message
news:BBCE9144.B64C%sb***@niaid.nih.gov...
IS there a C# equivalent to the VB IsNumeric function?



Nov 17 '05 #4
That's the idea. However, I need to do that on a string. I guess I could use
the String.ToCharArray() method first or use a loop.
Thanks,
Stephan.

in article ue**************@TK2MSFTNGP11.phx.gbl, Wim Hollebrandse at
wim@-NOSPAM-wimdows.net wrote on 11/5/03 12:42:
Try the static IsNumber() method on the Char class.
E.g.:

char c = 'a';
if (Char.IsNumber(c))
{
//do whatever...
}

Hope that helps.

Cheers,
Wim Hollebrandse
http://www.wimdows.net
http://www.wimdows.com

---
Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/


Nov 17 '05 #5
So, check TryParse

MSDN:
The TryParse method is like the Parse method, except this method does not
throw an exception if the conversion fails. If the conversion succeeds, the
return value is true and the result parameter is set to the outcome of the
conversion. If the conversion fails, the return value is false and the
result parameter is set to zero.

HTH

Alex

"Stephan Bour" <sb***@niaid.nih.gov> wrote in message
news:BBCEA49C.B6D7%sb***@niaid.nih.gov...
Actually, IsNumeric does two things: converts a string and returns a boolean true if the resulting expression is recognized as a number. Parse only
converts a string representation of a number to double. I need the boolean
return to validate a text box entry that can't be easily checked with a
validator.
Stephan.

in article eu**************@tk2msftngp13.phx.gbl, AlexS at
sa***********@SPAMsympaticoPLEASE.ca wrote on 11/5/03 14:39:
Check Parse and TryParse methods for corresponding types, Int, Long etc.

HTH
Alex

"Stephan Bour" <sb***@niaid.nih.gov> wrote in message
news:BBCE9144.B64C%sb***@niaid.nih.gov...
IS there a C# equivalent to the VB IsNumeric function?


Nov 17 '05 #6
Stephan Bour wrote:
IS there a C# equivalent to the VB IsNumeric function?


Follow this link:

http://groups.google.com/groups?selm...%40tkmsftngp09

--
mikeb

Nov 17 '05 #7
I apologize, I read TryParse too fast. You're right, it does what I need.
Thank you,
Stephan.

in article #I**************@TK2MSFTNGP10.phx.gbl, AlexS at
sa***********@SPAMsympaticoPLEASE.ca wrote on 11/5/03 16:18:
So, check TryParse

MSDN:
The TryParse method is like the Parse method, except this method does not
throw an exception if the conversion fails. If the conversion succeeds, the
return value is true and the result parameter is set to the outcome of the
conversion. If the conversion fails, the return value is false and the
result parameter is set to zero.

HTH

Alex

"Stephan Bour" <sb***@niaid.nih.gov> wrote in message
news:BBCEA49C.B6D7%sb***@niaid.nih.gov...
Actually, IsNumeric does two things: converts a string and returns a

boolean
true if the resulting expression is recognized as a number. Parse only
converts a string representation of a number to double. I need the boolean
return to validate a text box entry that can't be easily checked with a
validator.
Stephan.

in article eu**************@tk2msftngp13.phx.gbl, AlexS at
sa***********@SPAMsympaticoPLEASE.ca wrote on 11/5/03 14:39:
Check Parse and TryParse methods for corresponding types, Int, Long etc.

HTH
Alex

"Stephan Bour" <sb***@niaid.nih.gov> wrote in message
news:BBCE9144.B64C%sb***@niaid.nih.gov...
IS there a C# equivalent to the VB IsNumeric function?



Nov 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Lasse Edsvik | last post by:
Hello one question........ why does isnumeric return true? a="" if isnumeric(a) then response.write("test") end if empty isnt numerical is it??
3
by: Joel | last post by:
In VBA, you can use IsNumeric to return True or False if the value being tested is numeric. Is there an equivalent to this in VB.NET?
5
by: Steve Kershaw | last post by:
Hello, I have a need to see if a string is numeric or alphabetic. I understand that Visual Basic has a method called "IsNumeric(string)" but C# dosen't appear to have one. Any ideas? Thanks for...
7
by: Joe | last post by:
Hello All: Does anyone know how someone would check for a numeric value in .NET? In VB6, we used IsNumeric. What's the .NET equivalent? BTW, I know that I can harken back to IsNumeric. I'm...
9
by: Kimelia Schiles | last post by:
Hi, I am new to C#, and I am a VB programmer. I would like to know whether there is any function in C# that can is similar to IsNumeric in VB?
7
by: Vikas Kumar | last post by:
For Each item In Request.Form If IsNumeric(item) Then Try Approved(item) Catch ex As Exception Response.Write(ex.Message) End Try End If Next
3
by: Vikas Kumar | last post by:
For Each item In Request.Form If IsNumeric(item) Then Try Approved(item) Catch ex As Exception Response.Write(ex.Message) End Try End If Next
8
by: moondaddy | last post by:
What's the .net framework equivalent of the vb function isnumeric? If there isn't one, how can I test a string variable to see if its a number or not? I don't want to use isnumeric if possible ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.