C # Determines if a string can be converted to a number
<summary>/// determine if the string can be converted to digital///</summary>// <param name= "str" > the string to check </ param>// <returns>true: Can be converted to a number; false: not a number </returns> 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; }
Small bet
Double.tryparse method (String, NumberStyles, IFormatProvider, Double)
converts the string representation of a number in a specified style and culture-specific format to its double-precision floating-point count equivalent. A return value that indicates whether the conversion succeeded.
public static bool TryParse ( string s, NumberStyles style, IFormatProvider provider, out double result )
Parameters:
S: A String containing the number to convert.
style:A bitwise combination of the NumberStyles values that indicates the format that s is allowed to use. A typical value that is used to specify a combination of Float and allowthousands.
provider: A IFormatProvider that provides culture-specific formatting information about S.
result: When this method returns, contains a double-precision floating-point number equivalent to the numeric value or symbol contained in S if the conversion succeeds, or 0 if the conversion fails. If the s parameter is a null reference (Nothing in Visual Basic), its format does not conform to style, the number represented is less than MinValue or greater than MaxValue, or the style is not a valid combination of constants of the NumberStyles enumeration, the conversion fails 。 The parameter is passed without initialization.
return value
True if S is successfully converted; otherwise false.
The above is the C # to determine whether the string can be converted to digital content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!