Re: Creating an NSString from a data buffer
Re: Creating an NSString from a data buffer
- Subject: Re: Creating an NSString from a data buffer
- From: Vince DeMarco <email@hidden>
- Date: Tue, 17 Dec 2002 21:04:18 -0800
On Tuesday, December 17, 2002, at 08:47 PM, email@hidden wrote:
Hello!
Sorry for this newbie question, but I have been around
for quite a while, and I think I tried everything but
the
right thing.
I am building an object that can read / write a file
format that contains strings and binary codes.
At one point in the program, I have a buffer, which is
valid and contains the data I want. I want to extract an
unicode string from it. After having found the begin
and end positions of the string inside of the data
buffer, I would likw to create an NSString from it.
------
char * buffer; // My data buffer
NSString * S; // One NSString into which I want to
store data
char *begin;
char *end;
// At this pont, begin and end have been found and have
// the right values (end > begin)
// I tried, among many other things:
S = [NSString stringWithCharacters:begin
length:(end-begin)];
------
I tried the same, but with an alloc before calling
stringWithCharacters, etc...
Project builder keeps telling me that this method
(stringWithCharacters) cannot be found, although it
is in NSString.h:
+[NSString stringWithCharacters::]: selector not
recognized
Do I have to specify that I want to use some protocol?
Or some category?
I also thought I could maybe put all my data into an
NSString, maybe mutable, but my data does not correspond
to a string encoding...
Thanks for any help.
because its
+ (id)stringWithCharacters:(const unichar *)characters
length:(unsigned)length;
what you really want to do is allocate a data withe buffer
and then use NSStrings method
- (id)initWithData:(NSData *)data encoding:(NSStringEncoding)encoding;
So if the input file has different encodings, can you create a string
from it.
vince
_______________________________________________
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.