字符串 查询

int main(int argc, const char * argv[]) {

    @autoreleasepool {

     NSString*string=@"ghilsgfudr;ioabujfilbvj:user=admin&pwd=123";

        

    NSRange rang=[string rangeOfString:@"ioabujfilbvj"];

    

    if (rang.location==NSNotFound) {

        NSLog(@"未找到");

    }

    else

    {

        NSLog(@"location=%ld,length=%ld",rang.location,rang.length);

    }

    

    //快速输出范围

    NSLog(@"%@",NSStringFromRange(rang));

    

        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);

    

    return 0;

}

}

原文地址:https://www.cnblogs.com/haitong-0311/p/5120369.html