how to stop NSString/NSData from interpreting backslash
how to stop NSString/NSData from interpreting backslash
- Subject: how to stop NSString/NSData from interpreting backslash
- From: Ted Lowery <email@hidden>
- Date: Wed, 1 Oct 2003 00:43:24 -0400
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.