2

I have an attributedString with image attachments on it, and I need to insert text to it without removing the images. The first thing that I'm doing is detecting at what indexes the images are currently attached.

Below is the code that I'm using, but it is not working all of the time, maybe there is a better way?

 char charTemp;
    for(int i = 0; i < [mutableAttStr.string length]; i++){
        charTemp = [mutableAttStr.string characterAtIndex:i];

        if (!isalpha(charTemp) && !isspace(charTemp) && !iscntrl(charTemp) && !ispunct(charTemp)) {
       //     NSLog(@"isAttachment");
            [attachmentArrayCharIndex addObject:[NSNumber numberWithInt:i]];
        }
    }
4

1 回答 1

2

First, use unichar, not char.

Second, NSTextAttachment.h declares NSAttachmentCharacter which you can use to determine where an attachment is located in the attributed string.

于 2011-08-17T19:12:25.513 回答