开发者

NSString dataUsingEncoding not working?

I can't get this to work:

    NSString *string = @"!#€%&/()*^*_:;;:;_poawolwasnndaw";
    NSData *stringData = [string dataU开发者_开发知识库singEncoding:NSASCIIStringEncoding allowLossyConversion:NO];

stringData will be nil. Why?


According to the documentation, setting allowLossyConversion:NO yields the following potential behavior:

Returns nil if flag is NO and the receiver can't be converted without losing some information (such as accents or case).

In this case, the Euro symbol above has no ASCII equivalent, so the entire result will come back nil.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜