zoukankan      html  css  js  c++  java
  • OC编码问题输出中文

    #import <Foundation/Foundation.h>

    int main(int argc, const char * argv[]) {

        @autoreleasepool {

            NSMutableArray *arr=[NSMutableArray arrayWithObjects:@"中文",@"英文",@"编码", nil];

            NSLog(@"%@",arr);

            NSMutableDictionary *dic=[NSMutableDictionary dictionaryWithObjectsAndKeys:@"中文",@"one",@"编码",@"two",nil];

            NSLog(@"%@",dic);

            NSMutableSet *set=[NSMutableSet setWithObjects:@"中文",@"英文",@"编码", nil];

            NSLog(@"%@",set);

        }

        return 0;

    }


    出现编码问题,不能正常显示中文

    2016-07-21 22:19:48.117 测试[1618:495781] (

        "U4e2dU6587",

        "U82f1U6587",

        "U7f16U7801"

    )

    2016-07-21 22:19:48.117 测试[1618:495781] {

        one = "U4e2dU6587";

        two = "U7f16U7801";

    }

    2016-07-21 22:19:48.118 测试[1618:495781] {(

        "U7f16U7801",

        "U82f1U6587",

        "U4e2dU6587"

    )}

    Program ended with exit code: 0


    为数组添加类别


    #import "NSArray+ToChinese.h"           //类别名称

    @implementation NSArray (ToChinese)

    - (NSString *)descriptionWithLocale:(id)locale

    {

        NSMutableString *string=[[NSMutableString alloc]init];

        [string appendString:@"("];

        for (id obj in self) {              //self就是当前可变数组,遍历数组中的对象拼接成新的字符串返回

            [string appendFormat:@" %@",obj];

        }

        [string appendString:@" )"];

        return string;

    }

    @end


    为字典添加类别


    - (NSString *)descriptionWithLocale:(id)locale

    {

        NSMutableString *string=[[NSMutableString alloc]init ];

        [string appendString:@"{"];

        NSString* value=[NSString string];

        for (id obj in self) {                    //self就是当前可变字典,遍历字典中的对象拼接成新的字符串返回

            value=[self objectForKey:obj];

            [string appendFormat:@" %@ = %@",obj,value];

        }

        [string appendString:@" }"];

        return string;

    }


    为集合添加类别


    - (NSString *)descriptionWithLocale:(id)locale

    {

        NSMutableString *str=[[NSMutableString alloc]init];

        [str appendString:@"("];

        for(id obj in self) {                   //self就是当前可变集合,遍历集合中的对象拼接成新的字符串返回

            [str appendFormat:@" %@",obj];

        }

        [str appendString:@" )"];

        return str;

    }


    正常显示中文

    2016-07-21 22:18:58.727 编码问题[1572:488898] (

    中文

    英文

    编码

    )

    2016-07-21 22:18:58.728 编码问题[1572:488898] {

    one = 中文

    two = 编码

    }

    2016-07-21 22:18:58.728 编码问题[1572:488898] (

    编码

    英文

    中文

    )

    Program ended with exit code: 0

  • 相关阅读:
    麒麟短线王实战技法
    Silverlight的资源
    Windows Live SkyDrive, Windows Live Sync 和 Live Mesh
    Listview.Subitem.BackColor.ForeColor改变字体颜色和背景
    windows mobile控制面板程序
    Windows Azure百度百科
    wcf中如何Host多个WCF服务?
    强弱跟踪
    修改默认的HTTP Response Header
    DataTable 内部索引已损坏
  • 原文地址:https://www.cnblogs.com/lyjpost/p/5693404.html
Copyright © 2011-2022 走看看