查找字符串中需要的东西
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSString *string=@"http://localhost:8099/test/user=admin&pwd=123";
NSRange rang1=[string rangeOfString:@"user="];
NSRange rang2=[string rangeOfString:@"&pwd="];
NSUInteger userLocation=rang1.length+rang1.location;
NSUInteger userLength=rang2.location-(rang1.location+rang1.length);
NSRange userRang={userLocation,userLength};
NSString *user=[string substringWithRange:userRang];
NSLog(@"%@",user);
/* NSRange rang=[string rangeOfString:@"localhost:8099"];
if (rang.location==NSNotFound) {
NSLog(@"未找到");
}else{
NSLog(@"location=%ld,length=%ld",rang.location,rang.length);
//快速输出范围
NSLog(@"%@",NSStringFromRange(rang));
}*/