C # Determines if a string can be converted to a number

Source: Internet
Author: User
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)!

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