Professional Web Applications Themes

Cocoa: simple HTML text to Unicode - Mac Programming

I have an NSString. 99% of the time it contains just text. Sometimes one or more characters of the string will be encoded in HTML, like the following: Time for Questions & Answers. What's the simplest method I can use to turn this into normal text (I assume Unicode) ? There will never be any image or link information in the string, just encoded text....

  1. #1

    Default Cocoa: simple HTML text to Unicode

    I have an NSString. 99% of the time it contains just text.
    Sometimes one or more characters of the string will be encoded
    in HTML, like the following:

    Time for Questions & Answers.

    What's the simplest method I can use to turn this into normal
    text (I assume Unicode) ? There will never be any image or
    link information in the string, just encoded text.


    Simon Slavin Guest

  2. #2

    Default Re: Cocoa: simple HTML text to Unicode

    In article <BB8179049668744EF610.0.1.2>,
    [email]slavinshearsay.demon.co.uk[/email]localhost (Simon Slavin) wrote:
    > I have an NSString. 99% of the time it contains just text.
    > Sometimes one or more characters of the string will be encoded
    > in HTML, like the following:
    >
    > Time for Questions &amp; Answers.
    >
    > What's the simplest method I can use to turn this into normal
    > text (I assume Unicode) ? There will never be any image or
    > link information in the string, just encoded text.
    One likely approach is as follows, though I have not tried it:

    1. Load the NSString into an NSAttributedString, using
    NSAttributedString's -initWithHTML:doentAttributes initializer.

    2. Follow that by converting the attributed string back to an
    un-attributed one.

    --
    Tom "Tom" Harrington
    Macaroni, Automated System Maintenance for Mac OS X.
    Version 1.4: Best cleanup yet, gets files other tools miss.
    See [url]http://www.atomicbird.com/[/url]
    Tom Harrington Guest

  3. #3

    Default Re: Cocoa: simple HTML text to Unicode

    <slavinshearsay.demon.co.uk> wrote:
    > I have an NSString. 99% of the time it contains just text. Sometimes one
    > or more characters of the string will be encoded in HTML, like the
    > following:
    >
    > Time for Questions &amp; Answers.
    >
    > What's the simplest method I can use to turn this into normal text (I
    > assume Unicode) ? There will never be any image or link information in
    > the string, just encoded text.
    Search the string for HTML-encoded character entities and then convert
    them. :-) Numeric entities are assumed to be Unicode. Details:
    <http://makeashorterlink.com/?M10E233D5>

    Look at NSScanner, for some clues about how you might accomplish this.
    Paul Mitchum Guest

  4. #4

    Default Re: Cocoa: simple HTML text to Unicode

    In article <BB8179049668744EF610.0.1.2>,
    [email]slavinshearsay.demon.co.uk[/email]localhost (Simon Slavin) wrote:
    > What's the simplest method I can use to turn this into normal
    > text (I assume Unicode) ? There will never be any image or
    > link information in the string, just encoded text.
    My dirty little trick for this (used in STXML) was to note that Apple
    provides a perfectly fine entity decoder for XML to handle property
    lists, although they don't provide a detached interface to it. So I do
    something like:

    decodedString = [[NSString stringWithFormat: "<string>%</string>",
    encodedString] propertyList];
    Doc O'Leary Guest

Similar Threads

  1. Cannot read Unicode from html blog
    By Magnus_Lewan@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 5
    Last Post: September 18th, 12:13 PM
  2. Unicode Text Issues with ASP/ADO
    By Oleg in forum ASP Database
    Replies: 2
    Last Post: June 3rd, 10:46 PM
  3. increase the text box size-simple html help!
    By Aaron Bertrand - MVP in forum ASP
    Replies: 0
    Last Post: August 20th, 03:10 PM
  4. Converting simple text to HTML
    By Boris Zakharin in forum ASP.NET General
    Replies: 1
    Last Post: July 25th, 07:47 PM
  5. [cocoa richt text] named styles
    By Tobias Weber in forum Mac Programming
    Replies: 0
    Last Post: July 19th, 05:39 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139