打印字符串文字unicode作为实际字符

打印字符串文字unicode作为实际字符

本文介绍了打印字符串文字unicode作为实际字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Java应用程序中,我传递了一个如下所示的字符串:

In my Java application I have been passed in a string that looks like this:

\ u00a5123

当将该字符串打印到控制台时,我得到与输出相同的字符串(如预期的那样)。

When printing that string into the console, I get the same string as the output (as expected).

但是,我想要打印出来将unicode转换为实际的日元符号(\ u00a5 - >日元符号) - 我将如何进行此操作?

However, I want to print that out by having the unicode converted into the actual yen symbol (\u00a5 -> yen symbol) - how would I go about doing this?

即所以它看起来像这样:[日元符号] 123

i.e. so it looks like this: "[yen symbol]123"

推荐答案

我写了一个小程序:

public static void main(String[] args) {
    System.out.println("\u00a5123");
}

它的输出:

¥123

ie它输出的确与您在帖子中说明的内容完全相同我不确定是否还有其他事情发生。您使用的是哪个版本的Java?

i.e. it output exactly what you stated in your post. I am not sure there is not something else going on. What version of Java are you using?

编辑:

为了回应您的澄清,有一对不同的技术。最简单的方法是查找\ u后跟4个十六进制代码字符,提取该片段并用带有十六进制代码的unicode版本替换(使用Character类)。这当然假设字符串前面没有\ u。

In response to your clarification, there are a couple of different techniques. The most straightforward is to look for a "\u" followed by 4 hex-code characters, extract that piece and replace with a unicode version with the hexcode (using the Character class). This of course assumes the string will not have a \u in front of it.

我不知道任何特定的系统要解析String,就像它是一个编码的Java字符串。

I am not aware of any particular system to parse the String as though it was an encoded Java String.

这篇关于打印字符串文字unicode作为实际字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 02:44