• 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: want backslash in NSString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: want backslash in NSString


  • Subject: Re: want backslash in NSString
  • From: Fritz Anderson <email@hidden>
  • Date: Sun, 30 Dec 2001 20:40:27 -0600

On Sunday, December 30, 2001, at 08:02 PM, Christopher Anand wrote:

How do I get a backslash in an NSString?

I have tried the following:
...
string = [NSString stringWithCString: "\\include" length:8];
NSLog(string);

This is a right way to create an NSString with the value
\include
. If you're just coding an NSString constant, of course, you'd just say @"\\include".

Take notice that the first argument to NSLog is an NSString containing printf-style format. Using the format parameter to output the contents of NSString variables _almost_ works, just as
printf(stringvar);
_almost_ works with char * variables (it misbehaves if stringvar points to a string containing a %). So you'd prefer
NSLog(@"%@", string);
or
NSLog(@"%s", [string cString]);
. And instead of stringWithCString:length:, you'd prefer the NSString constant @"\\include".

2001-12-30 20:41:38.145 CircleView[403] \\\\include

Ouch. Looks like a bug in NSLog to me (NSLog(@"%@", @"\\include") does the same), though older heads can probably adduce a Very Good Reason for this behavior.
printf([@"\\include" cString]);
prints
\include
as expected.

-- F


References: 
 >want backslash in NSString (From: Christopher Anand <email@hidden>)

  • Prev by Date: Re: want backslash in NSString
  • Next by Date: Re: Apple's Address Book File Format
  • Previous by thread: Re: want backslash in NSString
  • Next by thread: Re: want backslash in NSString
  • Index(es):
    • Date
    • Thread