Best implementation for an isNumber(string) method

前端 未结 19 2540
感动是毒
感动是毒 2020-12-15 20:04

In my limited experience, I\'ve been on several projects that have had some sort of string utility class with methods to determine if a given string is a number. The idea h

19条回答
  •  南方客
    南方客 (楼主)
    2020-12-15 20:08

    Using .NET, you could do something like:

    private bool isNumber(string str)
    {
        return str.Any(c => !char.IsDigit(c));
    }
    

提交回复
热议问题