[英]Counting commas in between
我感覺菜鳥如何計算逗號? 我不知道該怎么做。 我想要看起來像這樣的代碼。
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 = ???;
}
我該怎么做?
NSArray * foo = [str componentsSeparatedByString:@","];
label.text = [NSString stringWithFormat:@"Found %d commas", [foo count] -1];
NSString componentsSeparatedByCharactersInSet:
或componentsSeparatedByString:
並獲取返回數組的大小。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.