EvilZone
Programming and Scripting => .NET Framework => : bubzuru August 03, 2012, 01:48:11 AM
-
do i realy need to explain ?
public bool IsNumeric(string str)
{
foreach (Char c in str)
{
if (!Char.IsNumber(c))
{
return false;
}
}
return true;
}
-
I don't want to sound rude or anything, but why? A quick Google search would yeild the same thing, or a we quick glance of the doc's.
Either way, I've noticed a lot more activity from you. Nice.
-
I don't want to sound rude or anything, but why? A quick Google search would yeild the same thing, or a we quick glance of the doc's.
Either way, I've noticed a lot more activity from you. Nice.
you would think so , but thats the thing there is no inbuilt IsNumeric function in C#
that surprised me to, thats why i posted the function
-
seriously? no built-in function like that? :D lol, Microsoft...
-
There's no isNumeric function in Java either for the String class. You can use Integer.parseInt which will throw an exception if the string is not a number but that's a really bad use of exceptions. Added a function just like the on Bubzuru posted in my utility class last week.
P.s. There is a isNumeric() function the Apache StringUtils library.
-
Your method only works for integers. You should call it isInteger() instead of isNumeric(), otherwise a String like "1.3" will be considered as non-numeric.
-
Your method only works for integers. You should call it isInteger() instead of isNumeric(), otherwise a String like "1.3" will be considered as non-numeric.
^^ that is true , this function does not work for floating point numbers.
if anybody needs a workaround please post here
-
There's no isNumeric function in Java either for the String class. You can use Integer.parseInt which will throw an exception if the string is not a number but that's a really bad use of exceptions.
You can use the TryParse method instead, it will not throw exception.
Also, you could use the IsNumeric function of VisualBasic in your C# application. You would need to reference the visualbasic dll in your project
-
TryParse is a C# method, not Java.
-
TryParse is a C# method, not Java.
Yes sorry I've read Satan911's answer too fast. My answer are possibilities for C#