Identify if a string is a number

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

If I have these strings:

  1. \"abc\" = false

  2. \"123\" = true

  3. \"ab2\"

25条回答
  •  太阳男子
    2020-11-22 00:37

    You can always use the built in TryParse methods for many datatypes to see if the string in question will pass.

    Example.

    decimal myDec;
    var Result = decimal.TryParse("123", out myDec);
    

    Result would then = True

    decimal myDec;
    var Result = decimal.TryParse("abc", out myDec);
    

    Result would then = False

提交回复
热议问题