【发布时间】:2012-11-22 11:08:12
【问题描述】:
我想从电话号码的国家/地区代码中删除前面的零。 我把它当作 NSString 因为电话号码包含诸如 + 、 ( 、 ) 、 - 之类的符号。 我需要那些符号。
例如
输入:-
1) NSString *phNo = @"0011234567890";
2) NSString *phNo2 = @"0601234567999";
输出:-
1) 11234567890
2) 601234567999
我做的如下
if ([phNo length]>10) {
NSString *countryCodeSubString = [phNo substringToIndex:[phNo length]-10];
if ([[countryCodeSubString substringToIndex:1]isEqualToString:@"0"]) {
for (int i=0; i<[countryCodeSubString length]; i++) {
NSString *str = [countryCodeSubString substringToIndex:i];
if ([str isEqualToString:@"0"]) {
str = [str stringByReplacingOccurrencesOfString:@"0" withString:@""];
}
}
}
}
我知道上面的代码是错误的。 有人可以帮我吗?我怎样才能有效地做到这一点?
【问题讨论】:
-
您可能想使用
hasPrefix方法。
标签: objective-c ios5 nsstring phone-number country-codes