首页 > 代码库 > OC各种数据类型之间的转换方法
OC各种数据类型之间的转换方法
NSNumber转NSString:
假设现有一NSNumber的变量A,要转换成NSString类型的B
方法如下:
NSNumberFormatter* numberFormatter = [[NSNumberFormatteralloc] init];
B = [numberFormatter stringFromNumber:A];
[numberFormatter release];
nsstring和float 还有int之间的转换
NSString *tempA = @"123";
NSString *tempB = @"456";
1,字符串拼接
NSString *newString = [NSString stringWithFormat:@"%@%@",tempA,tempB];
2,字符转int
int intString = [newString intValue];
3,int转字符
NSString *stringInt = [NSString stringWithFormat:@"%d",intString];
4,字符转float
float floatString = [newString floatValue];
5,float转字符
NSString *stringFloat = [NSString stringWithFormat:@"%f",intString];
///////[plain] view plaincopyprint?
- NSString *a = [[NSString alloc] initWithString : @"5, 10, 2, 0, 0, 0.01, 1, 0.05, 0, 0, 0"];
- NSArray *bullteData = http://www.mamicode.com/[a componentsSeparatedByString:@","];
- [a release];
- for (int i = 0; i < [bullteData count]; i++) {
- NSLog(@"%f",[[NSString stringWithFormat:@"%@",[bullteData objectAtIndex:i]] floatValue]);
- }
[plain] view plain copy
print?
- NSString *a = [[NSString alloc] initWithString : @"5, 10, 2, 0, 0, 0.01, 1, 0.05, 0, 0, 0"];
- NSArray *bullteData = [a componentsSeparatedByString:@","];
- [a release];
- for (int i = 0; i < [bullteData count]; i++) {
- NSLog(@"%f",[[NSString stringWithFormat:@"%@",[bullteData objectAtIndex:i]] floatValue]);
- }
OC各种数据类型之间的转换方法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。