NSNumber轉(zhuǎn)NSString:
假設(shè)現(xiàn)有一NSNumber的變量A卓箫,要轉(zhuǎn)換成NSString類型的B
方法如下:
NSNumberFormatter* numberFormatter = [[NSNumberFormatteralloc] init];
B = [numberFormatter stringFromNumber:A];
[numberFormatter release];
nsstring和float 還有int之間的轉(zhuǎn)換
NSString *tempA = @"123";
NSString *tempB = @"456";
1,字符串拼接
NSString *newString = [NSString stringWithFormat:@"%@%@",tempA,tempB];
2垄潮,字符轉(zhuǎn)int
int intString = [newString intValue];
3烹卒,int轉(zhuǎn)字符
NSString *stringInt = [NSString stringWithFormat:@"%d",intString];
4,字符轉(zhuǎn)float
float floatString = [newString floatValue];
5魂挂,float轉(zhuǎn)字符
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 = [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]);
}
將字符串存到數(shù)組中甫题,在讀取的時候轉(zhuǎn)換成需要的類型。
轉(zhuǎn)載自:http://blog.csdn.net/guozh/article/details/7822646