开发者

Is there a method for adding one NSString for NSData?

开发者 https://www.devze.com 2023-03-16 10:18 出处:网络
I\'m working on writing to a file one user input on a textField. So far I have one NSFileManager which writes data to a file. Still, 开发者_JAVA技巧I have no way of putting the textField input inside

I'm working on writing to a file one user input on a textField. So far I have one NSFileManager which writes data to a file. Still, 开发者_JAVA技巧I have no way of putting the textField input inside a file.

Is there a way do add a string value to NSData so I can write it?


you can get NSData from NSString,

NSData *newData = [yourString dataUsingEncoding:NSUTF16StringEncoding];

use encoding that fits your case. append the obtained data to existing NSData,

[existingData appendData:newData]

Note: "existingData" should be an instance of NSMutableData.


Use below code as your reference.

NSString* myString   = @"Is there a method for adding one NSString for NSData";
NSData* myData=   [myString dataUsingEncoding:NSUTF8StringEncoding];
0

精彩评论

暂无评论...
验证码 换一张
取 消