////// Determine whether a string can be converted to a number //////String to be checked///
True: It can be converted to a number. false: it is not a number.
Public static bool IsNumberic (string str) {double vsNum; bool isNum; isNum = double. tryParse (str, System. globalization. numberStyles. float, System. globalization. numberFormatInfo. invariantInfo, out vsNum); return isNum ;}
Note:
Double. TryParse method (String, NumberStyles, IFormatProvider, Double)
Converts the string representation of numbers in the specified style and culture-specific format to its equivalent double-precision floating point number. A return value indicating whether the conversion is successful.
public static bool TryParse ( string s, NumberStyles style, IFormatProvider provider, out double result)
Parameter: s: string containing the number to be converted.
Style: The bitwise combination of NumberStyles values, indicating the formats allowed by s. A typical value is a combination of Float and AllowThousands.
Provider: An IFormatProvider that provides information about the specific format settings of s.
Result: When this method is returned, if the conversion is successful, it contains the double-precision floating point number equivalent to the value or symbol contained in s; if the conversion fails, it contains zero. If the s parameter is a null reference (Nothing in Visual Basic), its format does not conform to the style, indicating that the number is smaller than MinValue or greater than MaxValue, or the style is not a valid combination of NumberStyles enumerated constants, the conversion fails. This parameter is passed without initialization.
Return Value
If s is successfully converted, the value is true; otherwise, the value is false.