基本数据类型应用(int ,float,double ,NSString,NSNumber)
People *stu=[People new];
NSLog(@"%@",stu.description);
//define double
NSNumber *num=[NSNumber numberWithDouble:[@"10" doubleValue]];
NSLog(@"%@",num);
NSString *n=@"9.000";
double dn=[n doubleValue];
dn=sqrt(dn);
NSLog(@"dn:%f",dn);
int d=[n intValue];
NSLog(@"%d",d);
float f=[@"9a" floatValue];
NSLog(@"%f",f);
NSLog(@"ok...");
//
long fileId=2115004;
NSNumber *file=[[NSNumber alloc]initWithLong:fileId];
fileId=[file longValue];
result:
2013-06-16 12:28:45.573 SDKDemo[523:c07] name:ketty,age:30
2013-06-16 12:28:45.578 SDKDemo[523:c07] 10
2013-06-16 12:28:45.579 SDKDemo[523:c07] dn:3.000000
2013-06-16 12:28:45.581 SDKDemo[523:c07] 9
2013-06-16 12:28:45.582 SDKDemo[523:c07] 9.000000
2013-06-16 12:28:45.583 SDKDemo[523:c07] ok...
NSString *n=@"9.000";
double dn=[n doubleValue];
dn=sqrt(dn);
NSLog(@"dn:%f",dn);
dn=sin([@"90.0" doubleValue]);
NSLog(@"dn:%f",dn);
字符串分割
NSString *str=@"<p>haha<br/></p>";
NSCharacterSet *charset=[NSCharacterSet characterSetWithCharactersInString:@"<p/br>"];
NSArray *array=[str componentsSeparatedByCharactersInSet: charset];
NSLog(@"array=%@",array);
for (NSString *string1 in array) {
if ([string1 length]>0) {
NSLog(@"string=%@",string1);
}
}
NSString *strhello=@"hello wor ld";
NSCharacterSet *set2=[NSCharacterSet whitespaceAndNewlineCharacterSet];
// set2=[NSCharacterSet characterSetWithCharactersInString:@"w"];
NSArray *arr=[strhello componentsSeparatedByCharactersInSet:set2];
NSMutableString *newStr=[NSMutableString string];
for(NSString *s in arr){
[newStr appendString:s];
}
NSLog(@"newStr=%@",newStr);
result:
2013-06-16 13:29:10.341 SDKDemo[653:c07] name:ketty,age:30
2013-06-16 13:29:10.347 SDKDemo[653:c07] array=(
"",
"",
"",
haha,
"",
"",
"",
"",
"",
"",
"",
"",
""
)
2013-06-16 13:29:10.348 SDKDemo[653:c07] string=haha
2013-06-16 13:29:10.349 SDKDemo[653:c07] newStr=hello or ld
2013-06-16 13:29:10.351 SDKDemo[653:c07] ok...
NSEnumerator:
NSString *strhello=@"hello wor ld";
NSCharacterSet *set2=[NSCharacterSet whitespaceAndNewlineCharacterSet];
// set2=[NSCharacterSet characterSetWithCharactersInString:@"w"];
NSArray *arr=[strhello componentsSeparatedByCharactersInSet:set2];
NSEnumerator *myEnumerator=[arr objectEnumerator];
NSString *now;
while ((now=[myEnumerator nextObject])) {
NSLog(@"myE-now=%@",now);
}
result:
2013-06-16 13:41:45.107 SDKDemo[703:c07] myE-now=hello
2013-06-16 13:41:45.109 SDKDemo[703:c07] myE-now=wor
2013-06-16 13:41:45.111 SDKDemo[703:c07] myE-now=ld