一:NSString转为基本数据类型
int a = [str intValue];
float a = [str floatValue];
BOOL a = [str boolValue];
二:基本数据类型转为NSString
NSNumber转NSString:
NSNumberFormatter* numberFormatter = [[NSNumberFormatteralloc] init];
B = [numberFormatter stringFromNumber:A];
nsstring和float 还有int之间的转换
NSString *tempA = @"123";
NSString *tempB = @"456";
1,字符串拼接
NSString *newString = [NSString stringWithFormat:@"%@%@",tempA,tempB];
2,int转字符
NSString *stringInt = [NSString stringWithFormat:@"%d",intString];
3,float转字符
NSString *stringFloat = [NSString stringWithFormat:@"%f"
三:结构体转字符串
NSStringFromCGPoint(CGPoint point);
NSStringFromCGVector(CGVector vector);
NSStringFromCGSize(CGSize size);
NSStringFromCGRect(CGRect rect);
NSStringFromCGAffineTransform(CGAffineTransform transform);
NSStringFromUIEdgeInsets(UIEdgeInsets insets);
NSStringFromUIOffset(UIOffset offset);
四:字符串转结构体
CGPointFromString(NSString *string);
CGVectorFromString(NSString *string);
CGSizeFromString(NSString *string);
CGRectFromString(NSString *string);
CGAffineTransformFromString(NSString *string);
UIEdgeInsetsFromString(NSString *string);
UIOffsetFromString(NSString *string);
五:基本数据类型转NSNumber
+ (NSNumber *)numberWithChar:(char)value;
+ (NSNumber *)numberWithUnsignedChar:(unsigned char)value;
+ (NSNumber *)numberWithShort:(short)value;
+ (NSNumber *)numberWithUnsignedShort:(unsigned short)value;
+ (NSNumber *)numberWithInt:(int)value;
+ (NSNumber *)numberWithUnsignedInt:(unsigned int)value;
+ (NSNumber *)numberWithLong:(long)value;
+ (NSNumber *)numberWithUnsignedLong:(unsigned long)value;
+ (NSNumber *)numberWithLongLong:(long long)value;
+ (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value;
+ (NSNumber *)numberWithFloat:(float)value;
+ (NSNumber *)numberWithDouble:(double)value;
+ (NSNumber *)numberWithBool:(BOOL)value;
+ (NSNumber *)numberWithInteger:(NSInteger)value NS_AVAILABLE(10_5, 2_0);
+ (NSNumber *)numberWithUnsignedInteger:(NSUInteger)value NS_AVAILABLE(10_5, 2_0);
六:NSNumber转基本数据类型
@property (readonly) char charValue;
@property (readonly) unsigned char unsignedCharValue;
@property (readonly) short shortValue;
@property (readonly) unsigned short unsignedShortValue;
@property (readonly) int intValue;
@property (readonly) unsigned int unsignedIntValue;
@property (readonly) long longValue;
@property (readonly) unsigned long unsignedLongValue;
@property (readonly) long long longLongValue;
@property (readonly) unsigned long long unsignedLongLongValue;
@property (readonly) float floatValue;
@property (readonly) double doubleValue;
@property (readonly) BOOL boolValue;
@property (readonly) NSInteger integerValue NS_AVAILABLE(10_5, 2_0);
@property (readonly) NSUInteger unsignedIntegerValue NS_AVAILABLE(10_5, 2_0);
@property (readonly, copy) NSString *stringValue;
网友评论