java 如何在java字符串中使用下标?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31414960/
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-11-02 18:35:04  来源:igfitidea点击:

How to use subscript in java string?

javastringsubscript

提问by Pravin Gajbhiye

How can I write subscript characters in a Java string?

如何在 Java 字符串中写入下标字符?

For example, I have to write "CO2". How can I move 2to the bottom of CO?

例如,我必须写"CO2". 我怎样才能移动2到底部CO

回答by Andrew Tobilko

The Stringclass doesn't provide such operations. But you could use the Unicode Character 'SUBSCRIPT TWO' (U+2082):

String类不提供这样的操作。但是您可以使用Unicode 字符 'SUBSCRIPT TWO' (U+2082)

final String string = "CO\u2082"; // CO?

Also, you could create a Stringas an HTML snippet. For instance,

此外,您可以将 a 创建String为 HTML 片段。例如,

final String html = "CO<sub>2</sub>";