/* 基本数据类型与字符串的相互转换 基本数据类型(int,float,double char) 1> int类型转换成字符串 2> float->NSString 3> double->NSString 4> char->NSString 5> NSString->int 6> NSString->float 7>NSString->double 8>将字符串中的字母转化成大写 9>将字符串的字母转换成小写 10>将首字母大写 */ int main(int argc, const char * argv[]) { @autoreleasepool { int i = 5; NSString * str = [[NSString alloc] initWithFormat:@"%d",i]; NSLog(@"%@",str); float f = 9.8; NSString * str1 = [[NSString alloc] initWithFormat:@"%.2f",f]; NSLog(@"%@",str1); double d = 4.5677; NSString * str2 = [[NSString alloc] initWithFormat:@"%.6f",d]; NSLog(@"str2 %@",str2); char c = 'a'; NSString * str3 = [[NSString alloc] initWithFormat:@"%c",c]; NSLog(@"%@",str3); NSString * str4 = @"10"; int i1 = [str4 intValue]; NSLog(@"%d",i1); NSString * str5 = @"1.5"; float f1 = [str5 floatValue]; NSLog(@"%.2f",f1); NSString * str6 = @"7.98"; double d1 = [str6 doubleValue]; NSLog(@"%.5f",d1); NSString * str7 = @"i386"; int i2 = [str7 intValue]; NSLog(@"%d",i2); NSString * str8 = @"baidu"; NSString * str9 = [str8 uppercaseString]; NSLog(@"%@",str9); NSString * str10 = @"CHINA"; NSString * str11 = [str10 lowercaseString]; NSLog(@"%@",str11); NSString * str12 = [str10 capitalizedString]; NSLog(@"%@",str12); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-12-25 20:04:50