开发者

decode base64 string as UTF-8

开发者 https://www.devze.com 2023-01-20 00:10 出处:网络
I am using the base64 implementation at the bottom of this post. If I use following code: NSLog(@\"decoded:%@\",[[[NSString alloc] initWithData:[Base64 decode:@\"8fEmIzEyNDA3OyYjMTI0MTE7\"] encoding

I am using the base64 implementation at the bottom of this post.

If I use following code:

NSLog(@"decoded:%@",[[[NSString alloc] initWithData:[Base64 decode:@"8fEmIzEyNDA3OyYjMTI0MTE7"] encoding:NSUTF开发者_开发问答8StringEncoding] autorelease]);

I get decoded:(null)

However, if I use:

NSLog(@"decoded 1:%@",[[[NSString alloc] initWithData:[Base64 decode:@"8fEmIzEyNDA3OyYjMTI0MTE7"] encoding:NSASCIIStringEncoding] autorelease]);

I get decoded:ññぷほ

But I should get decoded:ññぷほ

What am I doing wrong?


Those are HTML character references. You'll need to decode further if you want raw text.


You should read this article by Matt Gallagher. At the bottom there is link with code for iOS if that is what you are after.

It provides an class extension to NSData which is you string is easily converted from and too.

0

精彩评论

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