iphone跬步之--NSString

获取每段子字符串数组, 字符串被指定的字符分割(比如"\r\n")

NSArray *arr = [testStr componentsSeparatedByString:@"\r\n"];

 

字符串替换

NSString *str = [testStr stringByReplacingOccurrencesOfString:@"\\n" withString:@"\r\n"];

 

获取字符串@"testKey=testValue"中的key和value

NSString *testStr = @"testKey=testValue";
NSRange range = [testStr rangeOfString:@"=" options:NSLiteralSearch];
if (range.location != NSNotFound) {
    NSString *key = [testStr substringToIndex:range.location];    //从字符串开头开始,到index结束
    NSString *value = [testStr substringFromIndex:range.location + 1];   //从index开始,到字符串结束
}

 

比较字符串是否相等

- (NSComparisonResult)compare:(NSString *)string;
[testStr compare:testStr2] == NSOrderedSame

 

posted @ 2012-07-12 16:27  月光的尽头  阅读(577)  评论(0编辑  收藏  举报