In C#, how to check whether a string contains an integer?

后端 未结 8 1175
慢半拍i
慢半拍i 2020-12-28 12:43

I just want to know, whether a String variable contains a parsable positive integer value. I do NOT want to parse the value right now.

Currently I

相关标签:
8条回答
  • 2020-12-28 13:39

    The answer seems to be just no.

    Although there are many good other answers, they either just hide the uglyness (which I did not ask for) or introduce new problems (edge cases).

    0 讨论(0)
  • 2020-12-28 13:45

    Maybe this can help

    string input = "hello123world";
    bool isDigitPresent = input.Any(c => char.IsDigit(c));
    

    answer from msdn.

    0 讨论(0)
提交回复
热议问题