How to DELETE one emoji in NSString

前端 未结 4 1219
鱼传尺愫
鱼传尺愫 2020-12-28 11:02

How to Traversal emojis in NSString There is a NSString method used to traversal substring of NSString

    NSString *text = @\"2012         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-28 11:39

    Below is a solution based on Jesse Rusak's suggestion, however even the UITextInputTokenizer seems to be unable to properly parse the text, unless of course the error is on my part :)

    +(void)parse:(UITextField *)textfield {
        id tokenizer = [textfield tokenizer];
        UITextPosition *pos = textfield.beginningOfDocument;
    
        while (true) {
            UITextRange *range = [tokenizer rangeEnclosingPosition:pos withGranularity:UITextGranularityCharacter inDirection:UITextStorageDirectionForward];
            NSString *oneCharacter = [textfield textInRange:range];
    
            NSLog( @"%@", oneCharacter );
    
            pos = [textfield positionFromPosition:pos offset:-1];
    
            if (pos == nil) break;
        }
    }
    

提交回复
热议问题