Unicode symbol into NSTextField

Discussion in 'Mac Programming' started by i.yalovecky, May 31, 2010.

  1. i.yalovecky macrumors member

    Joined:
    Feb 24, 2010
    #1
    I have unicode code of symbol, for example 2605, how i can display it in NSTextField, thanks.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Something like this will get you an NSString. You should be able to do the rest (if you can't read the documentation):

    Code:
    unichar ch = 0x2605; 
    NSString*str = [NSString stringWithCharacters:&ch length:1];
    
     
  3. jamawa macrumors newbie

    Joined:
    Jul 7, 2009
    #3
    Another option is:

    Code:
    [theTextField setStringValue:[NSString stringWithFormat:@"Twinkle, twinkle, little %C", 0x2605]];
     
  4. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    Or use \u - for example this
    Code:
    @"Print\u2026"
    will give
    Code:
    @"Print…"
     
  5. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    The reason I used the solution I did is that some of the above depend on the source code file being UTF-8 and will break if it is not.

    Lot's of good discussion here.
     

Share This Page