整形字符串相互转化:
Convert Integer to NSString:
int Value = 112;
NSString *ValueString = [NSString stringWithFormat:@"%d", Value];
Convert NSString to C Integer:
int Value = 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