Java不可删除的空格字符串 [英] Java an unremoveable white space string

查看:70
本文介绍了Java不可删除的空格字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从mysql DB中获得了这个字符串:应该是这样:2100428169/2010

I have this string from mysql DB: it should be this: 2100428169/2010

这是我的代码

String str = rs.getString("str");
str = str.replaceAll("\\s+","");
str = str.trim();

char[] strCH = str.toCharArray();

我明白了:

[, 2, 1, 0, 0, 4, 2, 8, 1, 6, 9, /, 2, 0, 1, 0]

为什么?

这是一个问题,因为我需要使用str1.equals(str),但是它不起作用,因为在

It's a problem because I need to use str1.equals(str) but it doesn't work because after

Object obj = (object)str;

就像在我使用 toCharArray 时一样,它再次在obj中以空格开头,因此这意味着 equals 不起作用.

It is in obj again with a space at the beginning like when I use toCharArray so it means equals doesn't work.

推荐答案

我终于找到了解决方法:

I finally found solution:

这是有问题的,因为ASCII 65279是BOM的内容,trim()对此不起作用.

it was problem because of ASCII 65279 is something from BOM and trim() doesn't work for it.

这有帮助: str = str.replace("\ uFEFF",");

这篇关于Java不可删除的空格字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆