码迷,mamicode.com
首页 > 其他好文 > 详细

oc 笔记

时间:2014-11-01 11:25:06      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   ar   for   sp   strong   

整形字符串相互转化:

Convert Integer to NSString:

int Value = 112;
NSString *ValueString = [NSString stringWithFormat:@"%d", Value];

Convert NSString to C Integer:

int Value = 112;
int ValueString = [Value intValue];
char *ValueasCString = (char *)[ValueString UTF8String];

正则匹配:

search 模式:

 1 + (NSString *)getDomainOfEmailAddress:(NSString *)email
 2 {
 3     NSString *re = @"(?<=@)((?:[A-Za-z0-9]+(?:[\\-|\\.][A-Za-z0-9]+)*)+\\.[A-Za-z]{2,6})$";
 4     NSRange range = [email rangeOfString:re options:NSRegularExpressionSearch];
 5     if (range.location != NSNotFound) {
 6         return [email substringWithRange:range];
 7     }
 8     else {
 9         return nil;
10     }
11 }

match 模式:

+ (BOOL)isEmailAddress:(NSString *)email
{
    NSString *re = @"^([A-Za-z0-9\\.\\-_]{1,})@((?:[A-Za-z0-9]+(?:[\\-|\\.][A-Za-z0-9]+)*)+\\.[A-Za-z]{2,6})$";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", re];

    return [emailTest evaluateWithObject:email];
}

另外一篇待看的文章:

http://blog.devwu.com/develop/2014-05-29/use-regex-in-objective-c/

字符串输入:

char temp [100] = {0};
scanf("%s",temp);
NSString *str = [NSString stringWithUTF8String:temp];

 

字符串处理的另外两篇博客:

 

字符串拼接 : http://xys289187120.blog.51cto.com/3361352/676665

字符串拆分 : http://blog.sina.com.cn/s/blog_73eed198010101jz.html

oc 笔记

标签:style   blog   http   io   color   ar   for   sp   strong   

原文地址:http://www.cnblogs.com/MDK-L/p/4066520.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!