Hello, World! in Unicode?

  • Dear list,

    The XCode supplied template "Foundation Tool" does not do Unicode as I
    hoped. It prints the danish characters wrong.

    #import <Foundation/Foundation.h>

    int main (int argc, const char * argv[]) {
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

        NSLog(@"Hello, Jxrgen Xstergerd!"); //Name with 3 danish letters
        [pool release];
        return 0;
    }

    The C and C++ "Hello, World!" templates work.

    Thanks,
    Henrik
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • The ObjC static strings with the @"" notation doesn't support non-ASCII
    text. This is documented in the ObjC PDF. Suggestions for how to work
    around this can be found in the list archives.

    j o a r

    On 2004-08-09, at 11.07, Henrik Dalgaard wrote:

    > The XCode supplied template "Foundation Tool" does not do Unicode as I
    > hoped. It prints the danish characters wrong.
    >
    > #import <Foundation/Foundation.h>
    >
    > int main (int argc, const char * argv[]) {
    > NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    >
    > NSLog(@"Hello, Jxrgen Xstergerd!"); //Name with 3 danish letters
    > [pool release];
    > return 0;
    > }
    >
    > The C and C++ "Hello, World!" templates work.

    [demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • On 9 Aug 2004, at 10:07, Henrik Dalgaard wrote:

    > The XCode supplied template "Foundation Tool" does not do Unicode as I
    > hoped. It prints the danish characters wrong.
    ...
    > NSLog(@"Hello, Jxrgen Xstergerd!"); //Name with 3 danish letters

    The current compiler does not support non-ASCII characters in source
    files so you can't make Unicode string constants.  The proscribed
    method for dealing with this is to use the application localisation
    facilities.  So you might for instance use:
    NSLog(@"Hello, %@!", [[NSBundle mainBundle] localizedStringForKey:
    @"John Bull" value: nil table: nil]);
    and then put a mapping in the application bundle's Danish
    Localizable.strings between "John Bull" and "Jxrgen Xstergerd".

    Nicko
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • On 8 09, 2004, at 9:48, Nicko van Someren wrote:

    > On 9 Aug 2004, at 10:07, Henrik Dalgaard wrote:
    >
    >> The XCode supplied template "Foundation Tool" does not do Unicode as
    >> I hoped. It prints the danish characters wrong.
    > ...
    >> NSLog(@"Hello, Jxrgen Xstergerd!"); //Name with 3 danish letters
    >
    > The current compiler does not support non-ASCII characters in source
    > files so you can't make Unicode string constants.  The proscribed
    > method for dealing with this is to use the application localisation
    > facilities.  So you might for instance use:
    > NSLog(@"Hello, %@!", [[NSBundle mainBundle] localizedStringForKey:
    > @"John Bull" value: nil table: nil]);
    > and then put a mapping in the application bundle's Danish
    > Localizable.strings between "John Bull" and "Jxrgen Xstergerd".

    While it is best to use the localization system whenever possible,
    instead of hard-coding strings, it *is* possible to use non-ASCII
    characters in source, as long as you can ensure the encoding of the
    source file. For instance, if you know that the source code is in
    UTF-8, you can do the following:

    /*The characters may have been munged by the mailing list, but you get
    the idea*/
    NSString *foo = [NSString stringWithUTF8String: "String containing
    Unicode characters: $B;d$O%/%i!<%/$G$9!#(B"];

    This works especially well with UTF-8, as there is no way that any
    sequence of bytes can be mistakenly taken as an escape sequence (i.e.
    the only way that the byte representing the ASCII backslash can occur
    is if you've actually typed the backslash), you might not be so lucky
    with other multi-byte encodings.

    --
    Clark S. Cox III
    <clarkcox3...>
    http://www.livejournal.com/users/clarkcox3/
    http://homepage.mac.com/clarkcox3/

    [demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
previous month august 2004 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
MindNode
MindNode offered a free license !