iOS 问题:怎样从字符串中,提取数字出来
2016-11-21 · 学高端技术就来八维教育
关注
展开全部
你可以试试我这个代码,只取数字的方法 :
//号码显示格式
<br>
<br>+(NSString *)getPhoneNumberFomat:(NSString *)phone
<br>
<br>{
<br>
<br> if([phone length] <1)
<br>
<br> return nil;
<br>
<br> NSString* telNumber = @"";
<br>
<br> for (int i=0; i<[phone length]; i++) {
<br>
<br> NSString* chr = [phone substringWithRange:NSMakeRange(i, 1)];
<br>
<br> if([self doesStringContain:@"0123456789" Withstr:chr]) {
<br>
<br>/*if([telNumber length] == 3 || [telNumber length] == 8)
<br>
<br> telNumber = [telNumber stringByAppendingFormat:@"-%@", chr];
<br>
<br> else
<br>
<br> telNumber = [telNumber stringByAppendingFormat:@"%@", chr];*/
<br>
<br>telNumber = [telNumber stringByAppendingFormat:@"%@", chr];
<br>
<br> }
<br>
<br> }
<br>
<br> return telNumber;
<br>
<br>}
//号码显示格式
<br>
<br>+(NSString *)getPhoneNumberFomat:(NSString *)phone
<br>
<br>{
<br>
<br> if([phone length] <1)
<br>
<br> return nil;
<br>
<br> NSString* telNumber = @"";
<br>
<br> for (int i=0; i<[phone length]; i++) {
<br>
<br> NSString* chr = [phone substringWithRange:NSMakeRange(i, 1)];
<br>
<br> if([self doesStringContain:@"0123456789" Withstr:chr]) {
<br>
<br>/*if([telNumber length] == 3 || [telNumber length] == 8)
<br>
<br> telNumber = [telNumber stringByAppendingFormat:@"-%@", chr];
<br>
<br> else
<br>
<br> telNumber = [telNumber stringByAppendingFormat:@"%@", chr];*/
<br>
<br>telNumber = [telNumber stringByAppendingFormat:@"%@", chr];
<br>
<br> }
<br>
<br> }
<br>
<br> return telNumber;
<br>
<br>}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询