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