discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I make a NSString from a buffer?


From: Richard Frith-Macdonald
Subject: Re: How do I make a NSString from a buffer?
Date: Mon, 14 Apr 2003 12:36:59 +0100


On Monday, April 14, 2003, at 12:06  pm, Peter Karlsson wrote:

Dear list!

I allocate a memory buffer like this:

int len;
len = [myData length];
unsigned char *aBuffer;
aBuffer = malloc(len);

This buffer is 1000 bytes in length. I want to make a NSString with the contents of the first 6 bytes in aBuffer. How do I do that?

Depends on what is in the buffer.
If it's three unicode characters ... myString = [[NSString alloc] initWithCharacters: aBuffer length: 3]; If it's 6 bytes in the default character encoding ... myString = [[NSString alloc] initWithCString: aBuffer length: 6];
Both will copy the first six bytes from aBuffer into the string.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]