开发者

How to convert an NSString which is NSUTF8Encoded to NSASCIIEncoding in objective-c iPhone?

I have an NSString which contains data encoded with NSUTF8Encoding. I want to convert that string 开发者_Python百科into NSASCIIEncoding. Please tell me anyway to convert it in a proper manner. I am able to convert reverse (NSASCIIEncoding to NSUTF8Encoding).

Please provide any sample code.

Thanks in advance


I have an NSString which contains data encoded with NSUTF8Encoding.

Really? Because an NSString always treats its contents as UTF-16 internally. Because you cannot be sure how an NSString stores its data internally. Conceptually, NSString works with UTF-16.

I want to convert that string into NSASCIIStringEncoding.

if ([myString canBeConvertedToEncoding:NSASCIIStringEncoding]) {
    const char *asciiString = [myString cStringUsingEncoding:NSASCIIStringEncoding];
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜