/*截取字符串 从网址中截取用户名和密码*/
2 NSString *str=@"http://localhost:8090.cn?user=adminator&pwd=1234ABCD";
3 NSRange range1=[str rangeOfString:@"user="];
4 NSRange range2=[str rangeOfString:@"&pwd="];
5 NSUInteger userlocation=range1.location+range1.length;
6 NSUInteger userlength=range2.location-(range1.location+range1.length);
7 NSRange userRange={userlocation,userlength};// 自定义一个结构体范围
8 NSString *str1=[str substringWithRange:userRange];
9 NSLog(@"user=%@",str1);
10 NSUInteger strlen=[str length];
11 NSUInteger pwdlocation=userlength+userlocation+range2.length;
12 NSUInteger pwdlength=strlen-(userlength+userlocation+range2.length);
13 NSRange pwdRange={pwdlocation,pwdlength};// 自定义一个结构体范围
14 NSString *str2=[str substringWithRange:pwdRange];
15 NSLog(@"pwd=%@",str2);