Re: want backslash in NSString
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