Re: how to stop NSString/NSData from interpreting backslash
Re: how to stop NSString/NSData from interpreting backslash
- Subject: Re: how to stop NSString/NSData from interpreting backslash
- From: Joseph Jones <email@hidden>
- Date: Tue, 30 Sep 2003 21:56:34 -0700
Try using \\n instead. This will avoid the processing of \n as newline.
joe
On Tuesday, September 30, 2003, at 09:43 PM, Ted Lowery wrote:
Hi all-
I'm hoping someone can help me with the following code:
int x;
NSString* src = [NSString stringWithFormat:@"abc\n\ndef"];
for (x = 0; x < 10; x++)
{
printf("%i %c\n", x, [src characterAtIndex:x]);
}
What I had hoped to be printed was:
1 a
2 b
3 \
4 n
5 \
6 n
7 d
8 e
9 f
what was actually printed was:
0 a
1 b
2 c
3
4
5 d
6 e
7 f
*** Uncaught exception
I know, just escape the backslash with a \\.
Problem is, I am reading a source file and doing some analysis, and the
source file has lots of backslashes. I don't want those interpreted as
escape chars, I want to literally see the \ chr(92) and then read the
next char. I thought maybe NSString was "helping me out", so I read in
the file as NSData...
NSData* source = [NSData dataWithContentsOfFile:filename];
char* p = (char*)[source bytes];
but p+x still evaluates the \ followed by an n as a carriage return
rather than two bytes of data, chr(92) followed by chr(110).
anyone have any ideas how to get around this?
Thanks, Ted
ted at elowery dot net
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
Thank you,
Joseph Jones
JTech Softworks, Inc. -
http://www.jtechsoftworks.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.