首页 > 代码库 > oc 笔记
oc 笔记
整形字符串相互转化:
Convert Integer to NSString:
int Value = http://www.mamicode.com/112;
NSString *ValueString = [NSString stringWithFormat:@"%d", Value];
Convert NSString to C Integer:
int Value = http://www.mamicode.com/112;
int ValueString = [Value int
Value];
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 笔记
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。