utf-32 java,如何在java中将UTF-16转换为UTF-32?

I have looked for solutions, but there doesn't seem to be much on this topic. I have found solutions that suggest:

String unicodeString = new String("utf8 here");

byte[] bytes = String.getBytes("UTF8");

String converted = new String(bytes,"UTF16");

for converting to utf16 from utf8, however, java doesn't handle "UTF32", which makes this solution unviable. Does anyone know any other way on how to achieve this?

解决方案

after searching I got this to work:

public static String convert16to32(String toConvert){

for (int i = 0; i < toConvert.length(); ) {

int codePoint = Character.codePointAt(toConvert, i);

i += Character.charCount(codePoint);

//System.out.printf("%x%n", codePoint);

String utf32 = String.format("0x%x%n", codePoint);

return utf32;

}

return null;

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值