• 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: String Constant containing 2 ASCII Control Chars
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: String Constant containing 2 ASCII Control Chars


  • Subject: Re: String Constant containing 2 ASCII Control Chars
  • From: Jean-Daniel Dupas <email@hidden>
  • Date: Thu, 4 Dec 2008 16:58:37 +0100


Le 4 déc. 08 à 16:42, Jerry Krinock a écrit :

I'd like to define a global string constant consisting of two ASCII start-of-text (STX, 0x02) characters.

The following ^code^ will create such a thing:

NSString* two = [[NSString alloc] initWithFormat:@"%C%C", 0x2, 0x2] ;


and I realize that I could put it in some +initialize method for a class that was "guaranteed" to be created, but that solution is rather fragile, non-portable, etc.

I also appreciate that I'm creating an object, but gee it's a really simple object, and since Xcode can do this:

NSString* const hello = @"Hello" ;

Is there a way to put non-printing characters in a constant string like that?


Yes, either using octal escape sequence

NSString *two = @"\2\2";

or hexa escape sequence

NSString *two = @"\x2\x2";



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >String Constant containing 2 ASCII Control Chars (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: NSTimer
  • Next by Date: Re: Asynchronous timers (without a run loop)
  • Previous by thread: String Constant containing 2 ASCII Control Chars
  • Next by thread: [NSButtonCell] How to ask for refresh when a window resigns from being the key window
  • Index(es):
    • Date
    • Thread