Converting NSString to NSData and vice versa

前端 未结 2 947
無奈伤痛
無奈伤痛 2021-01-02 04:15

I am having an issue while trying to convert NSString to NSData and vice versa. I am trying to store encrypted string to my database. For that I am

相关标签:
2条回答
  • 2021-01-02 04:55

    Please mind that NSASCIIStringEncoding and NSUTF8StringEncoding need to match the characters in the string.

    0 讨论(0)
  • 2021-01-02 05:12

    NSString to NSData:

    NSString* str= @"teststring";
    NSData* data=[str dataUsingEncoding:NSUTF8StringEncoding];
    

    NSData to NSString:

    NSString* newStr = [[NSString alloc] initWithData:theData
                                             encoding:NSUTF8StringEncoding];
    
    0 讨论(0)
提交回复
热议问题