Re: getting bytes from NSData appends some special characters at the end
Re: getting bytes from NSData appends some special characters at the end
- Subject: Re: getting bytes from NSData appends some special characters at the end
- From: Sudheer dantuluri <email@hidden>
- Date: Tue, 29 Aug 2006 12:30:47 +0530
Hi Chris .
Thanks for your reply .
my problem is solved.
Previously I'm trying to get the bytes and write the content to a
file using C code .
NSData *xmlData = [[category document]
XMLDataWithOptions:NSXMLNodePrettyPrint];
const char *content = (const char *)[xmlData bytes];
Now I've changed the above code to
NSData *xmlData = [[libraryObject libraryInfo]
XMLDataWithOptions:NSXMLNodePrettyPrint];
NSString *str = [[NSString alloc] initWithBytes:[xmlData bytes]
length:[xmlData length] encoding:NSUTF8StringEncoding];
const char *content = [str UTF8String];
and passing the content to a file .
This is working fine for me now .
Thanks & Regards
- Sudheer.
On 28-Aug-06, at 6:32 PM, Chris Suter wrote:
The [xmlData bytes] doesn't return a null terminated string which
is what %s of NSLog expects.
- Chris
On 28/08/2006, at 10:58 PM, Sudheer dantuluri wrote:
Hi All ,
I've a problem while reading bytes from NSData .
Here I'm getting NSData from an XMLDocument and trying to get
bytes from the data .
But some special characters are getting added to the bytes .
NSData *xmlData = [[category document]
XMLDataWithOptions:NSXMLNodePrettyPrint];
const char *content = (const char *)[xmlData bytes];
NSLog(@" ------ content ------ :%s",content);
Here I'm adding the log
2006-08-28 18:09:51.204 ------ content ------ :
<Category>
<ID>Downloads</ID>
<ParentID></ParentID>
<Name>Downloads</Name>
<Comments></Comments>
<Color>
<redComponent>0.000000</redComponent>
<greenComponent>0.000000</greenComponent>
<blueComponent>0.000000</blueComponent>
<alphaComponent>0.000000</alphaComponent>
</Color>
<Path>Downloads.xml</Path>
<IconPath>Downloads.tif</IconPath>
<Projects></Projects>
<Books></Books>
<Pages></Pages>
<Color></Color>
</Category>>ategory>±¡”°±¡”
The extra characters are in red.
please help me out in this issue .
Thanks in advance
Sudheer.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
systems.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden