IOS asc码替换

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了IOS asc码替换相关的知识,希望对你有一定的参考价值。

 

-(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码替换的主要内容,如果未能解决你的问题,请参考以下文章

phpcms网页替换验证码及搜索功能

phpcms网页替换验证码功能 及 搜索功能

ASM字节码操作 转换已有的类 修改方法 替换方法调用

自定制emoji替换系统的emoji键盘

使用maven替换项目依赖中的字节码

iOS Runtime之方法替换