• 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: Creating an NSString from a data buffer
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Prev by Date: Creating an NSString from a data buffer
  • Next by Date: Re: Creating an NSString from a data buffer
  • Previous by thread: Creating an NSString from a data buffer
  • Next by thread: Re: Creating an NSString from a data buffer
  • Index(es):
    • Date
    • Thread