himanth himanth - 1 year ago 71
Objective-C Question

How to know that string contains all zeros?

I have a call option in my app but sometimes I am getting phone number is like "000000000" . So at that case I have to disable call option for user.
But how to know that string contains all zeros?
Please help me. Thanks in advance.

Avi Avi
Answer Source

Replace all 0's with nothing and then check if the string length is zero.

NSString *phoneNumber = @"000000000";
NSString *testNumber = [phoneNumber stringByReplacingOccurencesOfString:@"0"

if (testNumber.length == 0) {
    // phoneNumber contains all zeroes.
else {
    // phoneNumber may be good.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download