• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: escape special characters in HTML
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: escape special characters in HTML


  • Subject: Re: escape special characters in HTML
  • From: Dominik Pich <email@hidden>
  • Date: Thu, 16 Nov 2006 15:18:32 +0100

Thanks!

Am Nov 16, 2006 um 3:15 PM schrieb Conor:

Surely there is an easy way of doing that?

There exists a function to escape to percent escapes, but this is not what
you want. I would recommend writing your own function and escaping them to
numerals instead of the word; i.e. "&#234;" as this can be done generically
in a loop without having to know that ~ is &Tilde; Here is my class method
that does just that:


+ (NSMutableString *)encodeHTML:(id)aString {
    NSMutableString *stringToEncode = [NSMutableString string];
    [stringToEncode setString:aString];

    unsigned int i, count = [stringToEncode length];
    for (i =0; i < count; i++) {

if ([stringToEncode characterAtIndex:i] > 127){
NSString *replaceString = [NSString stringWithFormat:@"&#%d;",
[stringToEncode characterAtIndex:i]];
[stringToEncode replaceCharactersInRange:NSMakeRange(i,1)
withString:replaceString];
count = [stringToEncode length];
i += [replaceString length] -1;
}
}


    return stringToEncode;
}


You might want to add the following line to encode the amp as well at the
beginning, depending on your needs:


[stringToEncode replaceOccurrencesOfString:@"&" withString:@"&amp;"
options:NSLiteralSearch range:NSMakeRange(0, [stringToEncode length])];



Regards, Conor http://www.bruji.com/


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Re: escape special characters in HTML (From: Conor <email@hidden>)

  • Prev by Date: Re: escape special characters in HTML
  • Next by Date: Re: [SOLVED] Re: escape special characters in HTML
  • Previous by thread: Re: escape special characters in HTML
  • Next by thread: NSURLConnection and NSURLDownload Authentication
  • Index(es):
    • Date
    • Thread