0 Members and 1 Guest are viewing this topic.
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.
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.
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.
TryParse is a C# method, not Java.