• 字符串与基本数据类型转换


    1.

    • - (NSUInteger)length;

      • 返回字符串的长度(有多少个文字)
    • - (unichar)characterAtIndex:(NSUInteger)index;

      • 返回index位置对应的字符

    2.字符串和其他数据类型转换

    • 转为基本数据类型
      • - (double)doubleValue;
      • - (float)floatValue;
      • - (int)intValue;
        NSString *str1 = @"110";
        NSString *str2 = @"10";
        int res = str1.intValue + str2.intValue;
        NSLog(@"res = %i", res);
        NSString *str1 = @"110";
        NSString *str2 = @"10.1";
        double res = str1.doubleValue + str2.doubleValue;
        NSLog(@"res = %f", res);
    • 转为C语言中的字符串

      - (char *)UTF8String;

       NSString *str = @"abc";
        const char *cStr = [str UTF8String];
        NSLog(@"cStr = %s", cStr);
        char *cStr = "abc";
        NSString *str = [NSString stringWithUTF8String:cStr];
        NSLog(@"str = %@", str);
  • 相关阅读:
    python基本数据类型剖析
    常用正则表达式
    python_re模块
    迭代器模式
    状态模式
    备忘录模式
    asp.net 发送邮件
    建造者模式
    抽象工厂模式
    摸板模式与钩子
  • 原文地址:https://www.cnblogs.com/xufengyuan/p/6623909.html
Copyright © 2020-2023  润新知