Objective-C – Convert NSString to int and Vice Versa

Objective-C – Convert NSString to int and Vice Versa

Convert NSString to int

view source print ?
1 NSString *aNumberString = @"123";
2 int i = [aNumberString intValue];

 

Convert int to NSString

view source print ?
1 int aNumber = 123;
2 NSString *aString = [NSString stringWithFormat:@"%d", aNumber];

你可能感兴趣的:(Objective-C – Convert NSString to int and Vice Versa)