开发者

I there a Java equivalent to the Objective-C stringWithUTF8String:?

开发者 https://www.devze.com 2023-03-26 09:06 出处:网络
I need to convert the following from Objective-开发者_StackOverflowC to Java: char key[] = {\'9\' + 1, \'U\' + 2, \'6\' + 3, \'S\' + 4, \'7\' + 5}

I need to convert the following from Objective-开发者_StackOverflowC to Java:

char key[] = {'9' + 1, 'U' + 2, '6' + 3, 'S' + 4, '7' + 5} return [NSString stringWithUTF8String:key]

I'm not sure how to go about this.. does anyone have any ideas?


Yes, public String(byte[] bytes, Charset charset), the constructor of String that receives char[] and charset as parameters.


You use the public String(byte[] bytes, String charsetName) constructor and pass "UTF-8" as the charset. Here is an example:

byte key[] = {'9' + 1, 'U' + 2, '6' + 3, 'S' + 4, '7' + 5};
return new String(key, "UTF-8");
0

精彩评论

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