• 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: Converting an HTML source string to a readable string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting an HTML source string to a readable string


  • Subject: Re: Converting an HTML source string to a readable string
  • From: Conor Dearden <email@hidden>
  • Date: Fri, 12 May 2006 11:09:27 +0200

Here you go, a function from DVDpedia flipped to be used backwards (I use it
to go from UTF-8 to HTML encoding):

Just add the following line after you get your string:

[self convertHTMLEncoding:MyString];

Add this function to your class:

- (NSString *)convertHTMLEncoding:(NSString *)aString {

    NSMutableString *tempMutableString = [NSMutableString
stringWithCapacity:150];
    [tempMutableString setString:aString];

while (YES) {
        int tempInt = 0;
        NSScanner *searchScanner = [NSScanner
scannerWithString:tempMutableString];
        [searchScanner scanUpToString:@"&#" intoString:nil];
        if ([searchScanner isAtEnd])
            break;
        [searchScanner setScanLocation:[searchScanner scanLocation] +2];
        [searchScanner scanInt:&tempInt];


        if (tempInt) {
            if ([tempMutableString replaceOccurrencesOfString:[NSString
stringWithFormat:@"&#%d;", tempInt] withString:[NSString
stringWithFormat:@"%C", tempInt]  options:NSLiteralSearch
range:NSMakeRange(0, [tempMutableString length])] == 0)
                    [tempMutableString
deleteCharactersInRange:NSMakeRange([searchScanner scanLocation] -2 ,2)];
        }
        else
            [tempMutableString
deleteCharactersInRange:NSMakeRange([searchScanner scanLocation] -2 ,2)];
    }
    return tempMutableString;
}

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

  • Follow-Ups:
    • Re: Converting an HTML source string to a readable string
      • From: Eric Morand <email@hidden>
  • Prev by Date: Re: Vertically-expanding NSTextField
  • Next by Date: Re: NSDrawer in System Pref Pane
  • Previous by thread: Re: Converting an HTML source string to a readable string
  • Next by thread: Re: Converting an HTML source string to a readable string
  • Index(es):
    • Date
    • Thread