加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – 如何从NSString获取整数的数字?

发布时间:2020-12-14 17:16:37 所属栏目:百科 来源:网络整理
导读:我有一个像NSString * str = @“123”这样的字符串.我想把这个字符串的数字填充到UIPickerView.But如何从这个字符串中获取数字?我添加了以下代码 - (void)pickerView:(UIPickerView *)pickerView didSelectRow: (NSInteger)row inComponent:(NSInteger)comp
我有一个像NSString * str = @“123”这样的字符串.我想把这个字符串的数字填充到UIPickerView.But如何从这个字符串中获取数字?我添加了以下代码

- (void)pickerView:(UIPickerView *)pickerView didSelectRow: (NSInteger)row inComponent:(NSInteger)component 
{
 int number = [str intValue];
 if(component == 0)
 {

 }
 else if(component == 1)
 {

 }
 else 
 {

 }
}

解决方法

请看这个..

NSMutableArray *arrNumbers = [[NSMutableArray] alloc] initWithCapacity:[YOURSTRING length]];

for (i=0;i<[YOURSTRING length];i++) 
{
? unichaar ch = [YOURSTRING characterAtIndex:i];
? NSLog(@"Processing charachter %c",ch);
? // If you really want
? [arrNumbers addObject:(id)ch];
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读