Reputation: 604
I have an array and the contents look something like this:
"user/01453303276519456080/state/com.google/starred",
"user/01453303276519456080/state/com.google/broadcast",
"user/01453303276519456080/label/comics",
"user/01453303276519456080/label/General News",
"user/01453303276519456080/label/iPhone Related News",
"user/01453303276519456080/label/Programming",
"user/01453303276519456080/label/Sports",
"user/01453303276519456080/label/Tech News",
"user/01453303276519456080/label/Tutorials",
"user/01453303276519456080/state/com.blogger/blogger-following"
I want to extract only the last words after "/" (e.g. General News, Programming, etc) The unique id after user/ will not be constant.
Can someone give me an idea to implement this?
Cheers, iSEE
Upvotes: 1
Views: 172
Reputation: 3960
for(int i=0;i<[myArray count];i++)
{
NSMutableArray *tempArray=[[[NSMutableArray alloc] init] autorelease];
string=[myArray objectAtIndex:i];
NSArray *arr=[string componentsSeparatedByString:@"/"];
tempArray=[arr objectAtIndex:([arr count]-1)];
}
Now this tempArray contains the last components as u want
Hope it will help u!
Upvotes: -1
Reputation: 12787
use this
for(int i=0;i<[yourArray count];i++)
{
NSMutableArray *tempArray=[[[NSMutableArray alloc] init] autorelease];
string=[yourArray objectAtIndex:i];
tempArray=[[string componentsSeparatedByString:@"/"] mutableCopy];
//use tempArray
}
now tempArray having all strings at different indexes, fetch them according to you
Upvotes: 2
Reputation:
Look at the lastPathComponent
method of NSString
. This should give you exactly what you want. If you need the other parts too you can use the method componentsSeperatedByString:
or use a NSScanner
.
Upvotes: 2
Reputation: 1851
You can use lastPathComponent
API of NSString over each strings of the array.
Upvotes: 3