gotnull
gotnull

Reputation: 27224

Objective-C/iPhone - String replacing

How would I go about removing the "&expires_in=87131" within the following NSString:

Obviously the value 87131 may change in the future and it's always the last part of the string as well.

NSString *accessToken = @"136369349714439%7C2.nNIKZW8Z7Yw_aaaffqKv7lVFYJg__.86400.1301824800-705896566%7Cp-z9A68pJqTDNjEMj0TrHogc2bw&expires_in=87131";
NSString *newStr = [accessToken stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

Upvotes: 0

Views: 318

Answers (2)

user94896
user94896

Reputation:

If the string is guaranteed to only have one ampersand in it:

NSArray *components = [accessToken componentsSeparatedByString:@"&"];
accessToken = [components objectAtIndex:0];

Upvotes: 2

Related Questions