我有一根绳子,有点像
JNDI Locations eis/FileAdapter,eis/FileAdapter used by composite
HelloWorld1.0.jar are not available in the
destination domain. eis/FileAdapter,eis/FileAdapter正在发生两次。我希望它被格式化为
JNDI Locations eis/FileAdapter used by composite
HelloWorld1.0.jar are not available in the
destination domain. 我试过下面的东西
String[ ] missingAdapters =((textMissingAdapterList.item(0)).getNodeValue().trim().split(","));
missingAdapters.get(0) 但我错过了第二部分有什么更好的方法来处理这件事吗?
发布于 2013-08-14 14:21:27
在你下面的评论中,你确认了重复的内容将通过逗号来表示。使用这些信息,应该可以(在大多数情况下):
String replaceCustomDuplicates(String str) {
if (str.indexOf(",") < 0) {
return str; // nothing to do
}
StringBuilder result = new StringBuilder(str.length());
for (String token : str.split(" ", -1)) {
if (token.indexOf(",") > 0) {
String[] parts = token.split(",");
if (parts.length == 2 && parts[0].equals(parts[1])) {
token = parts[0];
}
}
result.append(token + " ");
}
return result.delete(result.length() - 1, result.length()).toString();
}用你的例子做一个小演示:
String str = "JNDI Locations eis/FileAdapter,eis/FileAdapter used by composite";
System.out.println(str);
str = replaceCustomDuplicates(str);
System.out.println(str);以前的错误固定
发布于 2013-08-14 14:20:38
这应该可以做到:
String[] missingAdapters = ((textMissingAdapterList.item(0)).getNodeValue().trim().split(","));
String result = missingAdapters[0] + " " + missingAdapters[1].split(" ", 2)[1];假设这个双字符串中没有空格,那么您要省略。
https://stackoverflow.com/questions/18234103
复制相似问题