Identify if a string is a number

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

If I have these strings:

  1. \"abc\" = false

  2. \"123\" = true

  3. \"ab2\"

25条回答
  •  无人及你
    2020-11-22 00:34

    If you want to know if a string is a number, you could always try parsing it:

    var numberString = "123";
    int number;
    
    int.TryParse(numberString , out number);
    

    Note that TryParse returns a bool, which you can use to check if your parsing succeeded.

提交回复
热议问题