Finding out whether a string is numeric or not

前端 未结 18 1707
一个人的身影
一个人的身影 2020-12-07 15:24

How can we check if a string is made up of numbers only. I am taking out a substring from a string and want to check if it is a numeric substring or not.

NSS         


        
18条回答
  •  悲&欢浪女
    2020-12-07 15:49

    Test if a string is a number Might be Helpful

    int i = [@"12.3" rangeOfCharacterFromSet: [ [NSCharacterSet characterSetWithCharactersInString:@"0123456789."] invertedSet] ].location;
    
    if (i == NSNotFound) {
         //is a number
    }
    

提交回复
热议问题