开发者

Extracting a small segment of NSString

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/014533032765开发者_C百科19456080/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


You can use lastPathComponent API of NSString over each strings of the array.


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.


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


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜