Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
1.31/5 (4 votes)
See more:
THERE IS not work isnumeric function.
tell me which function i use to check the string is numeric or not
Posted
Updated 18-Mar-17 2:30am
Comments
Thanks7872 2-Sep-13 2:13am    
Tag the question properly. C# alone is not sufficient.
PIEBALDconsult 18-Mar-17 13:23pm    
Why would that matter?

 
Share this answer
 
Comments
Joezer BH 2-Sep-13 2:45am    
5ed!
The first link should be a Tip, but it's a great tip

E.g.: It will also approve strings like "11,234" as a number.
abbaspirmoradi 2-Sep-13 2:48am    
Thank you Canny :)
 
Share this answer
 
use the TryParse() functions of numeric data types, depending on the specific type you need. E.g.
C#
int result;
if (int.TryParse(myString, out result))
{
    //ok, do something
}
else
{
    //not an int
}
 
Share this answer
 
IF you wants be check out your entire string is numeric or not so use this function. I hope it's helping you.


C#
int n;
        bool isNumeric = int.TryParse("123a", out n);



Thank You......:-)
 
Share this answer
 
C#
using System.Text.RegularExpressions;

Regex regex = new Regex(@"^[0-9]+$");

private bool IsInteger(string str)
{
	try
	{
		if (String.IsNullOrWhiteSpace(str))
                {
			return false;
		}
		if(!regex.IsMatch(str))
		{
			return false;
		}
		
		return true;
                
	}
	catch(Exception ex)
	{
		MessageBox.Show(ex.Message);
	}
	
	return false;
	
}
 
Share this answer
 
C#
int result;
myString="123";
if (int.TryParse(myString, out result))
{
    Console.WriteLine("String is numeric");
}
else
{
    Console.WriteLine("String is non numeric");
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900