码迷,mamicode.com
首页 > 移动开发 > 详细

IOS asc码替换

时间:2016-06-20 15:44:46      阅读:406      评论:0      收藏:0      [点我收藏+]

标签:

 

-(void)click:(UIButton *)btn

{

    NSString *testStr = @">全等";

    

    NSStringEncoding encoding2 = NSUTF8StringEncoding;

    

    testStr = [testStr stringByReplacingOccurrencesOfString:@"\t" withString:@""];

    testStr = [testStr stringByReplacingOccurrencesOfString:@"\x15" withString:@""];

    testStr = [testStr stringByTrimmingCharactersInSet:[NSCharacterSet controlCharacterSet]];

    testStr = [testStr stringByTrimmingCharactersInSet:[NSCharacterSet controlCharacterSet]];

    

    

    testStr = [testStr stringByTrimmingCharactersInSet:[NSCharacterSet illegalCharacterSet]];

    testStr = [testStr stringByTrimmingCharactersInSet:[NSCharacterSet symbolCharacterSet]];

    testStr = [testStr stringByTrimmingCharactersInSet:[NSCharacterSet nonBaseCharacterSet]];

    testStr = [testStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    

    NSMutableString *newStr = [[NSMutableString alloc]initWithCapacity:1];

    

    for (int i = 0; i < [testStr length]; i++) {

        unichar c = [testStr characterAtIndex:i];

        

        

        if(c>=0 && c<=31)

        {

            continue;

        }

        

        [newStr appendString:[NSString stringWithFormat:@"%@", [testStr substringWithRange:NSMakeRange(i, 1)]]];

        

        int bytesLeng = [[testStr substringWithRange:NSMakeRange(i, 1)] lengthOfBytesUsingEncoding:encoding2];

        

        NSLog(@"testStr[%d]=%@ = %d,%d", i, [testStr substringWithRange:NSMakeRange(i, 1)], c, bytesLeng);

    }

    NSLog(@"%@=%d, %@=%d", testStr, [testStr length], newStr, [newStr length]);

    

    

    

}

IOS asc码替换

标签:

原文地址:http://www.cnblogs.com/xiangjune/p/5600601.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!