Reputation: 31
for (int i=0; i<[rawNumber length]; i++) {
NSString* chr = [rawNumber substringWithRange:NSMakeRange(i, 1)];
if(doesStringContain(@"0123456789", chr)) {
telNumber = [telNumber stringByAppendingFormat:@"%@", chr];
}
}
What's the logic of this? What does this argument return?
Upvotes: 3
Views: 116
Reputation: 636
Looks like it's stripping out all the non-numeric characters, to give you a plain old phone number.
I imagine telNumber is defined before this loop, and uses the value of telNumber somewhere else.
Lets say rawNumber
held the following value: (987)-654-3210
. The for loop runs 14 times total, since that's the length of rawNumber
. Each time through, the code gets a single character - the first time it gets the first character, the second time the second character, etc. Each time through the loop, the code checks if the character is in the string 0123456789
; if it is, then the code appends the character to the telNumber variable. If the character is not in the list of numbers (if it's (
or )
or -
in our example), then it's just discarded.
Upvotes: 5