计算之间的逗号
我感觉菜鸟。如何计算逗号?我不知道该怎么做。 我想要看起来像这样的代码。
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 = ???;
}
我该怎么办?
I'm feeling noob. How do I count commas? I don't know how to do it.
I want code that look something like this.
Label.text = found 4 commas!!
NSString *str = @"100,000,000,000,000";
NSRange detecting = [str rangeOfString:@","];
if (detecting .length > 0 ) {
// Count how many commas?
// label.text = ???;
}
Label.text = found 3 commas!!
NSString *str = @"100,000,000,000";
NSRange detecting = [str rangeOfString:@","];
if (detecting .length > 0 ) {
// Count how many commas?
// label.text = ???;
}
label.text = found 1 comma!!
NSString *str = @"100,000";
NSRange detecting = [str rangeOfString:@","];
if (detecting .length > 0 ) {
// Count how many commas?
// label.text = ???;
}
Entering noobie textbox ["343,433,463"] and I should have 2 commas.
NSString *str = noobie.text;
NSRange detecting = [str rangeOfString:@","];
if (detecting .length > 0 ) {
// Count how many commas?
// label.text = ???;
}
How do I this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
NSString
componentsSeparatedByCharactersInSet:
或componentsSeparatedByString:
并获取返回数组的大小。NSString
componentsSeparatedByCharactersInSet:
orcomponentsSeparatedByString:
and get the size of the array returned.