zoukankan      html  css  js  c++  java
  • (转)OC各种数据类型之间的转换方法

    NSNumber转NSString:

    假设现有一NSNumber的变量A,要转换成NSString类型的B

    方法如下:

    NSNumberFormatter* numberFormatter = [[NSNumberFormatteralloc] init];

    B = [numberFormatter stringFromNumber:A];

    [numberFormatter release];


    nsstring和float 还有int之间的转换

     

    NSString *tempA = @"123";

    NSString *tempB = @"456";


    1,字符串拼接

    NSString *newString = [NSString stringWithFormat:@"%@%@",tempA,tempB];


    2,字符转int

    int intString = [newString intValue];


    3,int转字符

    NSString *stringInt = [NSString stringWithFormat:@"%d",intString];


    4,字符转float

    float floatString = [newString floatValue];


    5,float转字符

    NSString *stringFloat = [NSString stringWithFormat:@"%f",intString];

     

    1 [plain] view plaincopyprint
    2 {
    3     NSString *a = [[NSString alloc] initWithString : @"5, 10, 2, 0, 0, 0.01, 1, 0.05, 0, 0, 0"];
    4     NSArray *bullteData = [a componentsSeparatedByString:@","];
    5     [a release];
    6     for (int i = 0; i < [bullteData count]; i++) {
    7     NSLog(@"%f",[[NSString stringWithFormat:@"%@",[bullteData objectAtIndex:i]] floatValue]);
    8     } 
    1 [plain] view plaincopyprint
    2     {
    3     NSString *a = [[NSString alloc] initWithString : @"5, 10, 2, 0, 0, 0.01, 1, 0.05, 0, 0, 0"];  
    4     NSArray *bullteData = [a componentsSeparatedByString:@","];  
    5     [a release];  
    6     for (int i = 0; i < [bullteData count]; i++) {  
    7     NSLog(@"%f",[[NSString stringWithFormat:@"%@",[bullteData objectAtIndex:i]] floatValue]);  
    8     }  
  • 相关阅读:
    MT9v024总结
    常用芯片电路知识汇总
    octopress 如何添加youku视频和本地视频(octopress how to add a youku video or a local video)
    MT9M021/MT9M031总结
    TC358746AXBG/748XBG 桥接器说明
    mipi 调试经验
    1‘b0 什么意思
    MIPI总结和MIPI规格说明书
    octopress添加回到顶部按钮
    CentOS软件安装目录查找
  • 原文地址:https://www.cnblogs.com/zhangdashao/p/4488160.html
Copyright © 2011-2022 走看看