`

ios--基本数据类型应用(int ,float,double ,NSString,NSNumber)

    博客分类:
  • ios
 
阅读更多

 

基本数据类型应用(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

 

分享到:
评论

相关推荐

    ios-YUDBModel.zip

    支持: (NSObject,NSArray,NSDictionary,NSData,NSString,NSNumber,NSURL,Int,double,long,float,Bool,char)类型 灵活: 支持反序列化json key替换,支持自设定主键,支持忽略模型存储字段,支持反序列化代理之定义...

    ios-一行代码实现新特性功能.zip

    -(instancetype)initWithNSArray:(NSMutableArray *)array withButtonSize:(CGSize)buttonSize withButtonTitle:(NSString *)buttonTitle withButtonImage:(NSString *)imageName withButtonTitleColor:(UIColor *)...

    ios-网络加载器.zip

    使用方法 只有hud隐藏后,才会去创建新的hud,否则一直复用一个hud,至于那个- (void)showTitle:(NSString *)title navigationBar:(BOOL)hiden; 是为了自己项目里加,防止位置错乱 /** * 只带文字提示 * * @...

    ios-WebView实现网页图片获取放大.zip

    获取某个标签的结点个数- (int)nodeCountOfTag:(NSString *)tag { NSString *jsString = [NSString stringWithFormat:@"document.getElementsByTagName('%@').length", tag]; int len = [[self ...

    ios-轻量级对象字典转换库.zip

    一、json、对象、字典等随意转换,容纳所有类型,包括常用的NSObject家族,基本数据类型int、long等,冷门的结构体、枚举等。 二、一行代码全自动转换。不管你的类中有数组、字典、其他对象类型还是基本类型,不管...

    ios初级笔记

    ios初级代码 1.oc中的set和get方法 1&gt;.首先NewFile创建类,选iOS中的Cocoa Touch,再点击Objective-C class,输入类名Student,作为NSobject(系统 自带)的子类 2&gt;.在.h中做方法的声明 在Student.h中: //@...

    ios-模型.zip

    [1]JSON -&gt; Model 最简单的字典转模型 [2]JSON字符串转模型 [3]模型中嵌套模型 [4]模型中有个数组属性,数组里面又要装着其他模型 ...如果你有什么疑问或者交流的话,可以加 IOS代码库开发群QQ:524884683

    ios-CCPPickerView.zip

    //在确定的回调中将选择的数据(左侧的数据,右侧的数据以及拼接完成的数据进行返回) //注意金额按万为单位返回,时间按月份为单位返回. //事例代码如下: - (IBAction)clickIt:(UIButton *)sender { ...

    boredboss-ios-sdk:适用于 iOS 应用程序的 Boredboss SDK

    无聊的老板 Boredboss是一种移动分析 SAAS,旨在衡量应用程序指标。安装BoredBoss 可通过。 要安装它,只需将以下行添加到您的 Podfile 中: pod "Boredboss-ios-sdk"文档该项目使用 AppleDocs 语法进行记录。 但这...

    ios-AlertView.zip

    -(void)ButtonDidCilckedWithCancleOrConfirm:(NSString *)states IsRemberMyChose:(BOOL)myChose { NSLog(@"%d",myChose); if ([states isEqualToString:@"cancle"]) { //点击取消按钮 }else { ...

    ios-tableView实现三级地市.zip

    alertVc.citySelectBlock = ^(NSString *provice, NSString *city, NSString *area, NSString *code){ weakSelf.valueLab.text = [NSString stringWithFormat:@"%@-%@-%@-%@", provice, city, area, code]; }; ...

    ios-YBUploadView 上传图片.zip

    图片选择上传 并显示 支持 UIImage NSString NSData 三种类型的图片 一句代码都不用写 直接在Xib中拖一个View 就行了 xib设置maxCount editEnabled属性 快速集成 /** UIImage NSString NSData */ @property ...

    ios-超简单一个方法实现播放动画.zip

    - (void)playAnimateWithName:(NSString *)name framesNumber:(int)frames { // 动画可能被打断 if (self.imageView.isAnimating) { return; } // 1.取出所有的这个动画相关的序列图片,生成一个数组用来存放...

    ios-超级简单的文本展示工具.zip

    如果喜欢,欢迎给个start。 /** * 显示一个纯文字消息 ... (void)showText:(NSString *)text ;... (void)showImageText:(NSString *)text imageName:(NSString *)imageName inView:(UIView *)superView ;

    ios-一个简单好用的选择器--LTPickerView.zip

    pickerView.block = ^(LTPickerView* obj,NSString* str,int num){ //obj:LTPickerView对象 //str:选中的字符串 //num:选中了第几行 NSLog(@"选择了第%d行的%@",num,str); UIAlertView* alert = [...

    ios-自定义倒计时.zip

    自定义倒计时视图,提供结束时间(两种格式NSDate,NSString),实现倒计时效果 JYCountDownView *view = [JYCountDownView loadCountDownView]; view.center = self.view.center; NSDate *endDate = [NSDate ...

    ios-MCAlart.zip

    [self AlerViewNSNotification:[NSString stringWithFormat:@"%@",data]]; }]; for (int i = 0; i ; i ) { alart.mcLayoutKeyBourd(i); } // alart.mcLayoutKeyBourd(0).mcLayoutKeyBourd(1)....

    ios-datePickerView.zip

    self.datePicker.sureBlock = ^(NSString *selectDateStr) { [weakself.showDateLabel setText:selectDateStr]; [UIView animateWithDuration:5 animations:^{ [weakself.datePicker removeFromSuperview]; ...

    Keychain-iOS-ObjC:一个简单的Objective-C包装器,用于在iOS中使用钥匙串

    Keychain-iOS-ObjC是用于在iOS中使用Keychain的简单Objective-C包装器, KFKeychain类能够保存,加载和从iOS Keychain中删除任意对象,包括NSString和NSDictionary 。 例子 假设我们要在iOS钥匙串中存储用户授权...

    ios-封装系统的alert--好用的alert.zip

    NSString* str = [alert textFieldAtIndex:0].text; NSLog(@"输入的文字是%@,点击了第%d个按钮",str,num); }]; break; case 2: [LTAlertView showConfigBlock:^(LTAlertView *alertView) { alertView....

Global site tag (gtag.js) - Google Analytics