Fastest way to check if string contains only digits

后端 未结 20 835
挽巷
挽巷 2020-12-04 09:07

I know a few ways how to check this. regex,int.parse,tryparse,looping.

can anyone tell me what is the fastest way to check?

the nee

20条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 09:43

    I like Linq and to make it exit on first mismatch you can do this

    string str = '0129834X33';
    bool isAllDigits = !str.Any( ch=> ch < '0' || ch > '9' );
    

提交回复
热议问题