简体   繁体   English

如何从Java中的字符串中删除不可见的[ZWSP]

[英]How to remove invisible [ZWSP] from string in Java

I have a String(assume str) received from some DB query.我从一些数据库查询中收到了一个字符串(假设 str)。 str = "+Aa​+Bk​+Bo​+Ac​+Lc​"; str = "+Aa​+Bk​+Bo​+Ac​+Lc​"; But if copied the same string to intelliJ, It shows the invisible chars in str但是如果将相同的字符串复制到 intelliJ,它会显示 str 中的不可见字符

在此处输入图像描述

I have to split this String (iestr) to String[] and then to List.我必须将此字符串(iestr)拆分为 String[],然后拆分为 List。 And getting this[ZWSP] in splatted Array and in converted List as well.并在 splatted Array 和转换后的 List 中获取 this[ZWSP]。 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.其他方法也很少,但是在将输出复制到 intelliJ IDE 时看到那些 [ZWSP] 特殊字符。 在此处输入图像描述 That is creating issue in further processing.这在进一步处理中产生了问题。

How Can be these spcl chars ie [ZWSP] removed to get List/Array like [, Aa​, Bk​, Bo​, Ac​, Lc​]如何删除这些 spcl 字符,即 [ZWSP] 以获取列表/数组,如[, Aa​, Bk​, Bo​, Ac​, Lc​]

Will Appreciate all suggestions/solutions to this problem.将欣赏此问题的所有建议/解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM