小知识

作者: 学习之路 | 来源:发表于2016-10-12 17:19 被阅读9次

1.从通讯录中读取电话号码,去掉数字之间的-

NSString *originalString = @"(123)123123abc";
NSMutableString *strippedString = [NSMutableString stringWithCapacity:originalString.length];
NSScanner *scanner = [NSScanner scannerWithString:originalString];
NSCharacterSet *numbers = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];

while ([scanner isAtEnd] == NO) {
    NSString *buffer;
    if ([scanner scanCharactersFromSet:numbers intoString:&buffer]) {
        [strippedString appendString:buffer];
    }else {
        scanner.scanLocation = [scanner scanLocation] + 1;
    }
}
NSLog(@"%@",strippedString);

2.正则判断:字符串只包含字母和数字

NSString *myString = @"Letter1234";
NSString *regex = @"[a-z][A-Z][0-9]";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];

if ([predicate evaluateWithObject:myString]) {
    //implement
}

3.NSNotificationCenter带参数发送

MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:moviePath]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie];
[theMovie play];

  • (void)myMovieFinishedCallback:(NSNotification *)aNotification {
    MPMoviePlayerController *theMovie = [aNotification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie];
    }

相关文章

  • 开发小知识(一)

    开发小知识(一) 开发小知识(一)

  • 小知识

    夏天来了,格式冰冻的饮品也都上市了,什么冰激凌,炒冰,格式各样五花八门,我们要知道冰冻食物温度是0摄氏度,而我们人...

  • 小知识

    1字母默认大写的问题 以前了布局文件里定义一个text为字母的时候,很烦人的,它显示出来的默认就是大写,好烦人。今...

  • 小知识

  • 小知识

    气们不听话,一直雨加雪,她呼出一口热气,还有半小时锅就煮开了。 她去洗澡,水声隐隐想起一首歌,跟着哼唱。 她再回厨...

  • 小知识

    按住鼻翼两侧可以止住打喷嚏。 头发顺着发根到发梢的方向洗会柔顺很多。 鞋垫经常拿出来晾一晾可以...

  • 小知识

    #微协小分享# 今天微协君在桂花树上看到了一种果子,第一次见到它的微协君表示很神奇。原来这种果子叫桂花果[并不简单...

  • 小知识

    瓶装饮料扭不开怎么办,拍几下瓶底就可以轻松扭开,因为拍瓶底就会有小气泡冒出在整个瓶子里面会产生挤压里使瓶盖向上挤压...

  • 小知识

    1.元宵节:Lantern Festival 2.刺绣:Embroidery 3.重阳节:Double-Ninth...

  • 小知识

    LNMP LNMP = Linux + Nginx + Mysql + PHP LAMP LAMP = Linux...

网友评论

      本文标题:小知识

      本文链接:https://www.haomeiwen.com/subject/mhviyttx.html