[英]How can append Data to NSmutableData in Cocoa
I want to add new NSdata = x20 (ASCII) , it's a space at last in NSMutableData to enough fixed byes. 我想添加新的NSdata = x20(ASCII),这是NSMutableData中最后一个空格,足够固定的byes。 Example: NSmuatabledata has 400 bytes, but i need this NSMutableData has 600 bytes.
示例:NSmuatabledata有400字节,但是我需要这个NSMutableData有600字节。 So that i want to add 200 byes (x20 in HEX) at last this nsmutableData.
所以我想最后添加nsbyableData 200 byby(十六进制中的x20)。 How can i do that?
我怎样才能做到这一点? please help me.
请帮我。 thanks in advance
提前致谢
// write xmlDoc to file
NSData* xmlData = [xmlDoc XMLDataWithOptions:NSXMLNodePreserveAll];
NSLog(@"xmlData %@",xmlData);
NSMutableData * datawrite = [xmlData mutableCopy ] ;
NSArray *array = [[NSArray alloc] init]; // i dont know how to add x20 (hex) to this array
[datawrite appendData:[[NSString stringWithFormat:@"%@", array] dataUsingEncoding:NSUTF8StringEncoding]];
NSMutableData *datawrite = ...
NSUInteger oldLength = [datawrite length];
NSUInteger newLength = 600;
if (newLength > oldLength ) {
// extend mutable data object:
[datawrite setLength:newLength];
// fill appended bytes with space characters:
char *bytes = [datawrite mutableBytes];
memset(bytes + oldLength, ' ', newLength - oldLength);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.