When programming, it is often encountered whether the characters in a string are all numbers (0-9), which is a very easy implementation, but the programmer will first think that this is the simple function? What can be used for ready-made functions? There is an isNumeric (Object) in VB.NET, only char.isnumber () that determines a single character () in C #, isNuMeric can determine the Double type of digital string, but cannot exclude the positive and decimal points, if the determination string is one The number of words is quite appropriate, but it cannot be used to determine if the string is composed of numbers. No ready-made method, I have to write a function yourself:
Public Static Bool IsNum (String Str) {for (INT i = 0; I You can also use the exception thrown with int32.parse () to judge: Try {Int32.Parse (TOBETESTED);} Catch {// has an exception, then it is not a number. } So, which way is the best? Each has a favorable. I wrote a program to test the time required for each method. The test program main () is as follows: