iOS Unicode 字符 处理


#define THEROWLENGTH    16

#define UnicodeSTART    9728 - 1


+ ( NSString  *)replaceUnicode:( NSString  *)unicodeStr {

    

    NSString *tempStr1 = [unicodeStr stringByReplacingOccurrencesOfString:@"\\u" withString:@"\\U"];

    NSString *tempStr2 = [tempStr1 stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];

    NSString *tempStr3 = [[@"\"" stringByAppendingString:tempStr2] stringByAppendingString:@"\""];

    NSData *tempData = [tempStr3 dataUsingEncoding:NSUTF8StringEncoding];

    NSString* returnStr = [NSPropertyListSerialization propertyListFromData:tempData

                                                           mutabilityOption:NSPropertyListImmutable

                                                                     format:NULL

                                                           errorDescription:NULL];

    

    //NSLog(@"Output = %@", returnStr);

    

    return [returnStr stringByReplacingOccurrencesOfString:@"\\r\\n" withString:@"\n"];

}

- (void)showUnicodeIcon

{

    j = THEROWLENGTH;

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT0), ^{

        NSTimer *timerRun = [NSTimer timerWithTimeInterval:3 target:self selector:@selector(timeShow) userInfo:nil repeats:YES];

        [[NSRunLoop currentRunLoopaddTimer:timerRun forMode:NSRunLoopCommonModes];

        [[NSRunLoop currentRunLooprun];

//        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:20.0]]; //主线程等待,但让出主线程时间片,然后过10秒后返回

    });

}

- (void)timeShow

{

    NSMutableString  *stirn2= [NSMutableString stringWithCapacity:0 ];

    

        for (int i = 1; i <= j; i++) {

            //i = 1 UnicodeSTART处进行调整

            [stirn2 appendFormat:@"\\u%x"UnicodeSTART + i % THEROWLENGTH + (THEROWLENGTH * (i / THEROWLENGTH)) ] ;

            

//            NSLog(@"the string is #### %@", stirn2);

            

            NSString *unicodeStringShow = [[self classreplaceUnicode:stirn2];

            

            if (i % THEROWLENGTH == 0) {

                NSLog(@"the unicode is %@", unicodeStringShow);

                        //回到主线程

                        dispatch_async(dispatch_get_main_queue(), ^{

                            //refresh UI

                            _label.font = [UIFont fontWithName:@"Helvetica" size:40.f];

                            _label.textAlignment = NSTextAlignmentLeft;

                            _label.numberOfLines = 0;//行数设置为1,不设置时系统会默认行数为1

//                            [_label sizeToFit];

                            _label.text = [NSString stringWithString:unicodeStringShow];

                            

                        });

            }

//            NSLog(@"the unicode is %@", unicodeString);

            

            if (i % THEROWLENGTH == 0 && (i != 0)) {

                //清空本String

                [stirn2 setString:@""];

//                NSLog(@"the string is ===%@", stirn2);

            }

            

        }

        j += 16;

    

    NSLog(@"%@"@"timeShow");

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值