【发布时间】:2021-09-04 13:32:55
【问题描述】:
我的字符串:
BByTTheWay 。我想拆分字符串 as B By T The Way BByTheWay 。这意味着如果我得到任何大写字母,我想拆分字符串,最后按原样放置主字符串。到目前为止,我在 java 中尝试过:
public String breakWord(String fileAsString) throws FileNotFoundException, IOException {
String allWord = "";
String allmethod = "";
String[] splitString = fileAsString.split(" ");
for (int i = 0; i < splitString.length; i++) {
String k = splitString[i].replaceAll("([A-Z])(?![A-Z])", " $1").trim();
allWord = k.concat(" " + splitString[i]);
allWord = Arrays.stream(allWord.split("\\s+")).distinct().collect(Collectors.joining(" "));
allmethod = allmethod + " " + allWord;
// System.out.print(allmethod);
}
return allmethod;
}
它给了我输出: B ByT The Way BByTTheWay。我认为 stackoverflow 社区可以帮助我解决这个问题。
【问题讨论】: