Identify if a string is a number

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

If I have these strings:

  1. \"abc\" = false

  2. \"123\" = true

  3. \"ab2\"

25条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 00:16

    Hope this helps

    string myString = "abc";
    double num;
    bool isNumber = double.TryParse(myString , out num);
    
    if isNumber 
    {
    //string is number
    }
    else
    {
    //string is not a number
    }
    

提交回复
热议问题