- (NSArray *)componentsSeparatedByString:(NSString *)separator
componentsSeparatedByString: 方法:返回一个数组,该数组包含由给定分隔符分割的接收器中的子字符串。
参数 separator:分隔符字符串。
返回值:一个包含来自接收器的已由分隔符分割的子字符串的NSArray对象。
讨论:数组中的子字符串按它们在接收器中出现的顺序出现。分隔符字符串的相邻出现在结果中产生空字符串。同样,如果字符串以分隔符开头或结尾,则第一个或最后一个子字符串为空。例如,以下代码片段:
NSString *list = @"Norman, Stanley, Fletcher";
NSArray *listItems = [list componentsSeparatedByString:@", "];
produces an array { @"Norman",@"Stanley", @"Fletcher" }.
If list begins with a comma and
space—for example, ", Norman, Stanley,
Fletcher"—the array has these
contents: { @"", @"Norman",
@"Stanley", @"Fletcher" }
If list has no separators—for example,
"Norman"—the array contains the string
itself, in this case { @"Norman" }.
Availability Available in Mac OS X v10.0 and later.
See Also:
componentsJoinedByString: (NSArray)
– pathComponents
Related Sample Code:
ColorMatching
CoreRecipes
iSpend
iSpendPlugin
QTKitMovieShuffler
Declared In NSString.h
来自NSString文档