如何从Java中的字符串中删除不可见的[ZWSP]
我从某个DB查询中收到了一个字符串(假设str)。 str =“ +aa +bk +bo +ac +lc”; 中显示隐形字符
但是,如果将相同的字符串复制到Intellij,它将在str
我必须拆分此字符串(iEstr)到字符串[],然后列出。 并在散布的数组中获得此[ZWSP],并在转换后的列表中获得。 还尝试了很少的/以下技术来修剪和删除它,但没有起作用。
String str = "+Aa+Bk+Bo+Ac+Lc";
String[] strArr = str.split("\\+");
List<String> splitStrList = Arrays.stream(str.split("\\+"))
.map(String::trim)
.collect(Collectors.toList());
---方法2
String[] array2 = Arrays.stream(strArr).map(String::trim).toArray(String[]::new);
String[] trimmedArray = new String[array2.length];
for (int i = 0; i < array2.length; i++) {
trimmedArray[i] = array2[i].trim();
}
List<String> trimmedArrayList = Arrays.asList(trimmedArray);
也很少有其他方法,但是在将输出复制到IntellijIDE时,看到这些[ZWSP]特殊字符。 在进一步处理中引起了问题。
这些SPCL chars如何被删除以获取列表/数组 [,AA,BK,BO,AC,LC]
将感谢所有有关此问题的建议/解决方案。
I have a String(assume str) received from some DB query.
str = "+Aa+Bk+Bo+Ac+Lc";
But if copied the same string to intelliJ, It shows the invisible chars in str
I have to split this String (i.e.str) to String[] and then to List.
And getting this[ZWSP] in splatted Array and in converted List as well.
Also tried few/following techniques to trim and remove this, but did not worked.
String str = "+Aa+Bk+Bo+Ac+Lc";
String[] strArr = str.split("\\+");
List<String> splitStrList = Arrays.stream(str.split("\\+"))
.map(String::trim)
.collect(Collectors.toList());
---Approach 2
String[] array2 = Arrays.stream(strArr).map(String::trim).toArray(String[]::new);
String[] trimmedArray = new String[array2.length];
for (int i = 0; i < array2.length; i++) {
trimmedArray[i] = array2[i].trim();
}
List<String> trimmedArrayList = Arrays.asList(trimmedArray);
Also few other approach, but while copying the output to intelliJ IDE seeing those [ZWSP] special chars.
That is creating issue in further processing.
How Can be these spcl chars i.e [ZWSP] removed to get List/Array like
[, Aa, Bk, Bo, Ac, Lc]
Will Appreciate all suggestions/solutions to this problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该角色称为零width space as @rogue certions。您可以使用Unicode字符将其删除:
或者您可以按照所需的方式将字符串分开:
然后处理数组。
看:
https://www.fileformat.info/info/info/info/info/info/info/info/info/unicode/char/ 200b/index.htm
That character it's called zero-width space as @Rogue mentions. You could use unicode character to remove it:
Or you could split the string like:
And then process the array as you need.
See:
https://www.fileformat.info/info/unicode/char/200b/index.htm