NSString 에서 어떤 문 자 를 찾 습 니 다.

1219 단어 NSString
NSString 에서 어떤 문 자 를 찾 습 니 다.
//      
NSString *fullString = @"http://www.baidu.com";

NSRange hRange = [fullString rangeOfString:@"h"];
NSLog(@"hRange location %d length %d", (int)hRange.location, (int)hRange.length);
//output: 2014-06-22 14:58:12.870 stringTest[2368:60b] hRange location 0 length 1

NSRange dotRange = [fullString rangeOfString:@"."];
NSLog(@"dotRange location %d length %d", (int)dotRange.location, (int)dotRange.length);
//output: 2014-06-22 14:58:12.871 stringTest[2368:60b] dotRange location 10 length 1

//    
//              ,location   0  

NSRange baiduRange = [fullString rangeOfString:@"baidu"];
NSLog(@"baiduRange location %d length %d", (int)baiduRange.location, (int)baiduRange.length);
//output: 2014-06-22 14:58:12.872 stringTest[2368:60b] baiduRange location 11 length 5

//    
NSLog(@"dot From %@", [fullString substringFromIndex:dotRange.location+dotRange.length]);
//output: 2014-06-22 14:58:12.872 stringTest[2368:60b] dot From baidu.com

NSLog(@"dot To %@", [fullString substringToIndex:dotRange.location]);
//output: 2014-06-22 14:58:12.873 stringTest[2368:60b] dot To http://www

좋은 웹페이지 즐겨찾기