Mal*_*ene 0 iphone cocoa objective-c nsstring
@"/News/some news text/"
@"/News/some other news text/"
@"/About/Some about text/"
@"/Abcdefg/Some abcdefg text/some more abcdefg text"
Run Code Online (Sandbox Code Playgroud)
如何剪切字符串的第一部分,以便最终得到以下字符串?
@"/News/"
@"/News/"
@"/About/"
@"/Abcdefg/"
Run Code Online (Sandbox Code Playgroud)
使用componentsSeparatedByString:
打破字符串,最多:
NSArray *components=[string componentsSeparatedByString:@"/"];
if ([components count]>=2) {
// Text after the first slash is second item in the array
return [NSString stringWithFormat:@"/%@/",[components objectAtIndex:1]];
} else {
return nil; // Up to you what happens in this situation
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4886 次 |
最近记录: |