Identify if a string is a number

前端 未结 25 3398
無奈伤痛
無奈伤痛 2020-11-22 00:13

If I have these strings:

  1. \"abc\" = false

  2. \"123\" = true

  3. \"ab2\"

25条回答
  •  执笔经年
    2020-11-22 00:35

    Pull in a reference to Visual Basic in your project and use its Information.IsNumeric method such as shown below and be able to capture floats as well as integers unlike the answer above which only catches ints.

        // Using Microsoft.VisualBasic;
    
        var txt = "ABCDEFG";
    
        if (Information.IsNumeric(txt))
            Console.WriteLine ("Numeric");
    
    IsNumeric("12.3"); // true
    IsNumeric("1"); // true
    IsNumeric("abc"); // false
    

提交回复
热议问题