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
How to use subscript in java string?
提问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 2
to the bottom of CO
?
例如,我必须写"CO2"
. 我怎样才能移动2
到底部CO
?
回答by Andrew Tobilko
The String
class 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 String
as an HTML snippet. For instance,
此外,您可以将 a 创建String
为 HTML 片段。例如,
final String html = "CO<sub>2</sub>";