Identify if a string is a number

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

If I have these strings:

  1. \"abc\" = false

  2. \"123\" = true

  3. \"ab2\"

25条回答
  •  一个人的身影
    2020-11-22 00:36

    You can use TryParse to determine if the string can be parsed into an integer.

    int i;
    bool bNum = int.TryParse(str, out i);
    

    The boolean will tell you if it worked or not.

提交回复
热议问题