Convert string to mutable data - objective c [dupl

2019-10-02 15:05发布

问题:

This question already has an answer here:

  • objective-c: how to assign string to NSMutableData? 4 answers

How to convert a string into mutable data in objective c

回答1:

You can do something like,

NSString *str = @"any string";

NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];

NSMutableData *mutableData = [data mutableCopy];;

Hope this will help :)



回答2:

You can convert NSString to NSData by using

NSString* str = @"mystring";
NSData* data = [str dataUsingEncoding:NSUTF8StringEncoding];
NSMutableData *yourdata = [data mutableCopy];

hope it helps you :)