[英]java replace special characters to text
我有以下代码将我输入的文本更改为大写
if(WrtMsg.isDisplayable()== true); {
//System.out.println(test.toString().toUpperCase());
RecView.setText(test.toString().toUpperCase());
}
现在我希望像星号(*)这样的特殊字符作为文本更改。 Example *
to ATX
... 所以 output 将显示为ATX
。
WrtMsg
是文本输入的jtextarea
, RecView
是jtextarea
显示的 jtextarea。
请问有什么帮助吗? 谢谢。
您是否考虑过在代码中手动更改它? 您可以创建这样的方法:
private String charToText(String character) {
character = character.replace("*", "ATX")
// and so forth...
return character;
}
只需使用String
class 的replaceAll
方法即可。 something.replaceAll(Pattern.quote("*"), "ATX")
。
if(wrtMsg.getText().contains("*"))
{
RecView.setText("ATX");
}
您应该使用字符串 object 的替换方法
test.toString().toUpperCase().replace("*", "ATX")
RecView.setText(wrtMsg.getText().replace("*", "ATX"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.