ios-字符串进阶

NSString *a = @”8e0c2412021270fb_gr_session_id=3bb8f9ed-0203-42e4-b25c-98e49206ec0e; 8e0c2412021270fb_gr_session_id_3bb8f9ed-0203-42e4-b25c-98e49206ec0e=true; _ResumeHack_session=am4rQW5SdldaQlQ5eHVpZ1dvWWx3ZE9Yc201WFlTLzBOVUdNMitsYU42UjJIUFU1djR4WDJUT0tvN0dUaVhtdFk1b1dkSE9DNEtXdlFHL2tNM3pLeFFPZ1JZMGlXUGwyUDhkUUVEUythcWoweThGTzBRWVNucDZVVUR4RXNyQVhxY0t2QXRBaEhHWDl6SEdyaGNwMHZJRjlJeVVGcWIwZlRCMWRvMStwNDJMeDIxaDl5bTJKN0NYMWQ0ejdlSlFSTHVUMU4zeEEzbmRXQUNyZGE0V2xyMVlKNzdWeXVqM0VIUmF1TmlybXRoUnNkVFhWNGxiVDNlOWVDYTRQeVFLdC0tVXlETG1xTjcvd25RVmlveFV0RHQxdz09–50662a5248ec2615aaf0098440ba6b9f02492971; __profilin=p%3Dt; gr_user_id=aa9e2d55-23c1-485a-bd88-c51f314824e2; grwng_uid=5d7e8aba-8f56-4950-975c-b8c44d85d7fb”;
NSString *b = @”_ResumeHack_session”;

NSString *c = @"__profilin";

NSString *d = [NSString stringWithFormat:@"%@%@",[self achieveStringWithRootString:a key:b],[self achieveStringWithRootString:a key:c]];
NSLog(@"----->%@",d);

}

  • (NSString *)achieveStringWithRootString:(NSString *)rootString
    key:(NSString *)key{
    NSRange aRange = [rootString rangeOfString:[NSString stringWithFormat:@”%@=”,key]];
    NSString *c = [rootString substringFromIndex:aRange.location];
    NSRange bRange = [c rangeOfString:@”;”];//匹配得到的下标
    NSString *d = [c substringToIndex:bRange.location + bRange.length];
    return d;
    }