Hello,
I have a need to see if a string is numeric or alphabetic. I understand
that Visual Basic has a method called "IsNumeric(stri ng)" but C#
dosen't appear to have one. Any ideas?
Thanks for your help
Steve 5 1624
Import Microsoft.Visua lBasic and use it!
if (Microsoft.Visu alBasic.Informa tion.IsNumeric( "5"))
{
//Do Something
}
if (Microsoft.Visu alBasic.Informa tion.IsNumeric( "yadda"))
{
//Do Something
}
Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Español : http://asp.net.do/foros/
=============== =============== ========
"Steve Kershaw" <st***********@ yahoo.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. . Hello, I have a need to see if a string is numeric or alphabetic. I understand that Visual Basic has a method called "IsNumeric(stri ng)" but C# dosen't appear to have one. Any ideas?
Thanks for your help
Steve
Steve,
Try this:
public static bool IsInteger(strin g theValue)
{
try
{
Convert.ToInt32 (theValue);
return true;
}
catch
{
return false;
}
}
}
"Steve Kershaw" wrote: Hello, I have a need to see if a string is numeric or alphabetic. I understand that Visual Basic has a method called "IsNumeric(stri ng)" but C# dosen't appear to have one. Any ideas?
Thanks for your help
Steve
From Scott Hanselman's blog at : http://www.hanselman.com/blog/Explor...mericForC.aspx
Actually, this doesn't really do what IsNumeric does,
as IsNumeric should also return true for floating point numbers.
That code does not return true for floating point numbers,
which -nevertheless- *are* numbers.
That is really more of an "IsInt".
Importing Microsoft.Visua lBasic does the complete job.
Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Español : http://asp.net.do/foros/
=============== =============== ========
"Dave" <Da**@discussio ns.microsoft.co m> wrote in message
news:D7******** *************** ***********@mic rosoft.com... Steve,
Try this:
public static bool IsInteger(strin g theValue) { try { Convert.ToInt32 (theValue); return true; } catch { return false; } } }
"Steve Kershaw" wrote:
Hello, I have a need to see if a string is numeric or alphabetic. I understand that Visual Basic has a method called "IsNumeric(stri ng)" but C# dosen't appear to have one. Any ideas?
Thanks for your help
Steve
In the .Net 2.0 CLR, there is an Int32.TryParse( ) method that doesn't throw
an exception, and you can use that. In .Net 1.1, you're pretty much stuck
with the alternatives that the others have already proposed.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.
"Steve Kershaw" <st***********@ yahoo.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. . Hello, I have a need to see if a string is numeric or alphabetic. I understand that Visual Basic has a method called "IsNumeric(stri ng)" but C# dosen't appear to have one. Any ideas?
Thanks for your help
Steve
There is no equivalent for this function in C#. VB.NET has lots of
functions that C# developers have to create manually.
Or, you can import the visual basic namespace and use its IsNumeric function
from within C#.
--
I hope this helps,
Steve C. Orr, MCSD, MVP http://SteveOrr.net
"Steve Kershaw" <st***********@ yahoo.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. . Hello, I have a need to see if a string is numeric or alphabetic. I understand that Visual Basic has a method called "IsNumeric(stri ng)" but C# dosen't appear to have one. Any ideas?
Thanks for your help
Steve This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: eje |
last post by:
IsNumeric(value) should return false if value "can not be
successfully converted to a Double." Instead I get the
following error message: "Input string was not in a
correct format."
I use the following function in a validating class to use
when needed. (Value = H880118A gave the error (like
other 'unconvertible' strings))
Public Function Numeric(ByVal value) As Boolean
|
by: Eugene Anthony |
last post by:
I have received the following feedback for the two functions bellow:
"The ISNUMERIC test is WORTHLESS for checking for an INT value, because
ISNUMERIC will happily accept DOUBLE values, such as 89.11998811777 and
other values that are simply *NOT* INT values."
<%
function isZip(input)
|
by: Kenny |
last post by:
Hello,
I would like to know if the function IsNumeric requires a header like
#include <iostream> to be functionnal
thanks
ken
|
by: John Bowman |
last post by:
Hello,
Does anyone have a good/reliable approach to implementing an IsNumeric()
method that accepts a string that may represent a numerical value (eg. such
as some text retrieved from an XML file)? Thus if you pass it "1" or
"5.12345" it returns true, but "1b3q" it returns false? I know VB has this
sort of function, but was wondering how to implement something similar in
C#. I suppose I could use the Convert methods and catch any...
|
by: martin |
last post by:
Hi,
is there a dotnet function (other than the old isnumeric from VB) to check
whether an object is numeric or not.
also I notice that all the old vb functions such as split / isnumeric /
ubound etc are still availible by default in any VB.net web application.
is this because the vb library is being imported??
would it be best to totally remove this library (assuming that it is being
imported - which I can't see in my references) so...
| |
by: Nathan Truhan |
last post by:
All,
I think I may have uncovered a bug in the IsNumeric function, or at least a
misunderstanding on functionality.
I am writing a Schedule Of Classes Application for our campus and have a
section that lists the Times, Buildings and rooms for courses.
In this section I have a function called PadCell that takes3 parameters, one
the value, one a padd count and one a a boolean input called StripNumeric,
that if true, checks if the value...
|
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
|
by: sck10 |
last post by:
Hello,
I am trying to determine if a value is NOT numeric in C#. How do you test
for "Not IsNumeric"?
protected void fvFunding_ItemInserting_Validate(object sender,
FormViewInsertEventArgs e)
if (e.NewValues != "" && Not IsNumeric(e.NewValues))
{
|
by: Paul |
last post by:
Hi,
I am trying to check a string to see if it's first 3 characters are numeric
and if they are, to replace those 3 characters with something else.
I've tried this but nothing happens...
newname = Replace(newname, VB.Left(newname, 3) = "101-", "101. ")
|
by: MLH |
last post by:
I have tested the following in immed window:
?isnumeric(1)
True
?isnumeric(1.)
True
?isnumeric(1.2)
True
?isnumeric(1.2.2)
|
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,...
| |
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...
|
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...
|
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,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |