473,835 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IsNumeric C# equivalent

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

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

HTH
Alex

"Stephan Bour" <sb***@niaid.ni h.gov> wrote in message
news:BBCE9144.B 64C%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***********@S PAMsympaticoPLE ASE.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.ni h.gov> wrote in message
news:BBCE9144.B 64C%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.ToCharAr ray() 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.ni h.gov> wrote in message
news:BBCEA49C.B 6D7%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***********@S PAMsympaticoPLE ASE.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.ni h.gov> wrote in message
news:BBCE9144.B 64C%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***********@S PAMsympaticoPLE ASE.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.ni h.gov> wrote in message
news:BBCEA49C.B 6D7%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***********@S PAMsympaticoPLE ASE.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.ni h.gov> wrote in message
news:BBCE9144.B 64C%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
7249
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
5209
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
1620
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 your help Steve
7
1908
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 trying to purge any trace of VB6 from my code. TIA, --
9
8987
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
1902
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
1363
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
2591
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 -- moondaddy@noemail.noemail
0
9653
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10815
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10526
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10563
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7770
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6970
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4435
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3999
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3094
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.