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

发布于 2025-02-13 20:16:13 字数 1298 浏览 1 评论 0原文

我从某个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

enter image description here

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.
enter image description here
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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

享受孤独 2025-02-20 20:16:13

该角色称为零width space as @rogue certions。您可以使用Unicode字符将其删除:

str.replace("\u200B", "");

或者您可以按照所需的方式将字符串分开:

str.split("\\+\u200B");

然后处理数组。

看:
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:

str.replace("\u200B", "");

Or you could split the string like:

str.split("\\+\u200B");

And then process the array as you need.

See:
https://www.fileformat.info/info/unicode/char/200b/index.htm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文