java 如何将 Unicode 无穷大符号转换为字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10806893/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 02:39:56  来源:igfitidea点击:

how can i get the Unicode infinity symbol converted to String

javastringnumbers

提问by Wandang

I want to use the infinity symbol (8 lying sideways) in java.

我想在 java 中使用无穷大符号(8 个侧身躺着)。

furthermore i want to use it as a String component.
i did not find a working charcode/ascii code for this (is there any?).

此外,我想将它用作字符串组件。
我没有找到一个有效的 charcode/ascii 代码(有吗?)。

i tried:

我试过:

String s=Character.toString(236);
String s=Character.toString('236');

am i missing something?

我错过了什么吗?

i got this now:

我现在得到了这个:

System.out.println(Character.toString('\u221E'));

but the output is ?

但输出是 ?

i am using java 1.7 jdk and eclipse. why is the infinity sign not showing up?

我正在使用 java 1.7 jdk 和 eclipse。为什么无穷大符号不显示?

回答by bmargulies

You need the Unicode infinity sign, U+221E. 236 is a Windows typing convention, that won't help you at all. '\u221e'is the character constant.

您需要 Unicode 无穷大符号U+221E。236 是 Windows 打字约定,它根本不会帮助你。'\u221e'是字符常量。

Now, I can't promise that this will result in any ∞ characters on your screen. That depends on what sort of computer you have, what font you are using, and what you set in -Dfile.encoding. Also see this question.

现在,我不能保证这会导致您的屏幕上出现任何 ∞ 个字符。这取决于您拥有哪种类型的计算机、您使用的字体以及您在 -Dfile.encoding 中设置的内容。另请参阅此问题

回答by ArifMustafa

I know this is very late reply but the below information will definitely help someone.

我知道这是很晚的回复,但以下信息肯定会对某人有所帮助。

In Eclipseby default Text File encoding for console is Cp1252, then

Eclipse默认情况下,文本文件编码为控制台Cp1252,然后

How to support UTF-8 encoding in Eclipse

如何在 Eclipse 中支持 UTF-8 编码

and I will encourage to handle the infinitysymbol in Stringlike below source:

我将鼓励infinityString如下源代码中处理符号:

String infinitySymbol = null;

try {

    infinitySymbol = new String(String.valueOf(Character.toString('\u221E')).getBytes("UTF-8"), "UTF-8");

} catch (UnsupportedEncodingException ex) {

    infinitySymbol = "?";
    //ex.printStackTrace(); //print the unsupported encoding exception.

} finally {

    System.out.print("Symbol of infinity is : " + infinitySymbol);

}