Problem displaying accented characters in NSTextView

  • In an app we are working on I read in files which may contain
    accented characters.  These are read into an NSString, which is then
    bound to an NSTextView.

    All works fine, except that accented characters are not displayed
    correctly.  For example an accented e (Ž) appears as a square root
    sign and a copyright symbol (é).  I would have expected this to
    'just work' but it doesn't!

    Any hints on how to get this to work would be greatly appreciated!

    Rick _______________________________________________
    Do not post admin requests to the list. They will be ignored.
    Cocoa-dev mailing list      (<Cocoa-dev...>)
    Help/Unsubscribe/Update your Subscription:
    http://lists.apple.com/mailman/options/cocoa-dev/<cocoa...>

    This email sent to <cocoa...>
  • Check for encoding of resource file !

    Regards,
    Mradul Mandhanya

    -----Original Message-----
    From: cocoa-dev-bounces+mmandhanya=<quark.com...> [mailto:cocoa-dev-bounces+mmandhanya=<quark.com...>] On Behalf Of Rick Hoge
    Sent: Friday, October 14, 2005 9:32 AM
    To: Cocoa-Dev Mail
    Subject: Problem displaying accented characters in NSTextView

    In an app we are working on I read in files which may contain
    accented characters.  These are read into an NSString, which is then
    bound to an NSTextView.

    All works fine, except that accented characters are not displayed
    correctly.  For example an accented e (¨¦) appears as a square root
    sign and a copyright symbol (¡Ì(c)).  I would have expected this to
    'just work' but it doesn't!

    Any hints on how to get this to work would be greatly appreciated!

    Rick _______________________________________________
    Do not post admin requests to the list. They will be ignored.
    Cocoa-dev mailing list      (<Cocoa-dev...>)
    Help/Unsubscribe/Update your Subscription:
    http://lists.apple.com/mailman/options/cocoa-dev/<mmandhanya...>

    This email sent to <mmandhanya...>
  • On Oct 13, 2005, at 9:01 PM, Rick Hoge wrote:

    > All works fine, except that accented characters are not displayed
    > correctly.  For example an accented e (Ž) appears as a square root
    > sign and a copyright symbol (é).  I would have expected this to
    > 'just work' but it doesn't!

    Be sure to create the string you display in the NSTextView using the
    correct string encoding.  There are a wide variety of different
    encodings that non-ASCII text can be stored in, with all sorts of
    subtle and not-so-subtle differences between them.

    I suspect the text is stored in the file using UTF-8 encoding but you
    created a string from it using MacRoman encoding, or something similar.

      -- Chris
  • Thanks for the replies - this was the culprit (and fix)!

    //NSString *result = [[NSString stringWithContentsOfURL:url] retain];
    NSString *result = [[NSString stringWithContentsOfURL:url
    encoding:NSUTF8StringEncoding error:nil] retain];

    On Oct 14, 2005, at 2:36 AM, Chris Hanson wrote:

    > On Oct 13, 2005, at 9:01 PM, Rick Hoge wrote:
    >
    >
    >> All works fine, except that accented characters are not displayed
    >> correctly.  For example an accented e (Ž) appears as a square root
    >> sign and a copyright symbol (é).  I would have expected this to
    >> 'just work' but it doesn't!
    >>
    >
    > Be sure to create the string you display in the NSTextView using
    > the correct string encoding.  There are a wide variety of different
    > encodings that non-ASCII text can be stored in, with all sorts of
    > subtle and not-so-subtle differences between them.
    >
    > I suspect the text is stored in the file using UTF-8 encoding but
    > you created a string from it using MacRoman encoding, or something
    > similar.
    >
    > -- Chris
    >
    >
    >
    >
previous month october 2005 next month
MTWTFSS
          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            
Go to today