我如何撤消split()方法或类似反向拆分()

时间:2017-01-18 13:34:11

标签: java

In this text file we will replace the word text with another word
But the number of times the text value is repeated depends on the user input

我的文本与文本文档(两行)完全相同。我想知道如何替换特定的单词取决于用户输入。

例如,用户想要在文本文档中用新词= java替换重复4次的单词“the”,如何替换所有“the”(?)?

结果将是

In this text file we will replace java word text with another word
But java number of times java text value is repeated depends on java user input

我发布了我的代码,但尚未完成,所以如果我发布它你可能会说与主题无关的内容

提前致谢

编辑:我已初始化String[] columnsString Line;我也写过Line = scan.nextLine();columns = Line.split(" ");

那就是将用户的输入与列[i]

进行比较

2 个答案:

答案 0 :(得分:1)

String source = "In this text file we will replace the word text with another word But the number of times the text value is repeated depends on the user input";

String result = source.replace("the", "java");

答案 1 :(得分:0)

您可以使用replaceAll() - 方法。