Numeric or not
How to check a field ..whether is it numberic or not. in Visaul Stdio2005 C#
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
SolitairePosted Feb 16, 2006, 1:41 PM
The following emulates the Val() function of VB. It returns the numeric value of a string up to the first non-numeric character. Otherwise it returns 0. It works with positive or negative numbers and will accept a single decimal point. However, you will probably prefer a bool method to emulate IsNumeric().
public
static double Valcs(string snum){
double vnum = 0; int N;snum = snum.Replace(" ", "");
N = snum.Length;
string[] anum = new string[N + 1]; for (int x = 1; x <= N; x++){
anum[x] = snum.Substring(0, x);
try{
vnum = Convert.ToDouble(anum[x]);
}
catch{
if(x != 0 && anum[x] != "-") break;}
}
return vnum;}
raihan68Posted Feb 16, 2006, 4:42 AM