【发布时间】:2015-05-01 18:58:49
【问题描述】:
嗯,我正在尝试使用 contains() 方法替换一个单词:
String z = tfB.getText().toString();
String show = textPane.getText().toString();
if(show.contains(z)){
// how I specify the word that were found and change it without
effecting anything with in that line
}
我的主要内容是:
我想做的是从用户那里获得价值。 然后搜索是否找到将其替换为某些内容。例如:
String x = "one two three four five";
它应该将 textPane 设置为"one two 3 four five"
或
"one two 3-three-3 four five"
谁能告诉我怎么做。
谢谢
【问题讨论】:
-
你在尝试替换之前不需要检查它是否存在。
-
包含不替换。 contains 仅告诉您某些文本是否包含字符串。通过阅读 String 的 javadoc,您应该能够找到对替换有用的方法。文档是程序员最好的朋友。阅读。它是为你写的。
标签: java swing user-interface replace contains