C # determine whether a string can be converted to a number

Source: Internet
Author: User

////// 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.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.