我感觉不舒服。如何计算逗号?我不知道该怎么做。我希望代码看起来像这样。
标签。文本=发现4个逗号!!
NSString *str = @"100,000,000,000,000";
NSRange detecting = [str rangeOfString:@","];
if (detecting .length > 0 ) {
// Count how many commas?
// label.text = ???;
}
标签。文本=发现3个逗号!!
NSString *str = @"100,000,000,000";
NSRange detecting = [str rangeOfString:@","];
if (detecting .length > 0 ) {
// Count how many commas?
// label.text = ???;
}
标签。文本=找到1逗号!!
NSString *str = @"100,000";
NSRange detecting = [str rangeOfString:@","];
if (detecting .length > 0 ) {
// Count how many commas?
// label.text = ???;
}
输入新文本框["343,433,463"],我应该有两个逗号。
NSString *str = noobie.text;
NSRange detecting = [str rangeOfString:@","];
if (detecting .length > 0 ) {
// Count how many commas?
// label.text = ???;
}
我该怎么做?
NSArray * foo = [str componentsSeparatedByString:@","];
label.text = [NSString stringWithFormat:@"Found %d commas", [foo count] -1];
NSString componentsSeparatedByCharactersInSet:
或componentsSeparatedByString:
,获取返回数组的大小。