如何删除  与Jsoup?

Car*_*oce 13 java jsoup

我不能用 .trim()等删除它!我不明白.

我甚至在Stackoverflow上找到了尝试,.replace(" ", "")但都没有工作.

我试过这个:

System.out.println( "'"+fields.get(6).text().replace("\\u00a0", "")+"'" ); //'94,00 '
System.out.println( "'"+fields.get(6).text().replace(" ", "")+"'" ); //'94,00 '
System.out.println( "'"+fields.get(6).text().trim()+"'"); //'94,00 '
System.out.println( "'"+fields.get(6).html().replace(" ", "")+"'"); //'94,00' works
Run Code Online (Sandbox Code Playgroud)

但我无法弄清楚为什么我无法删除空白区域\\u00a0.

T.J*_*der 19

你的第一次尝试非常接近,Jsoup映射 到U + 00A0 你是对的.您只是不希望字符串中出现双反斜杠:

System.out.println( "'"+fields.get(6).text().replace("\u00a0", "")+"'" ); //'94,00'
// Just one ------------------------------------------^
Run Code Online (Sandbox Code Playgroud)

replace不使用正则表达式,因此您不会尝试将文字反斜杠传递到正则表达式级别.您只想在字符串中指定字符U + 00A0.


Ovo*_*eta 6

使用JSoup库,

str.replaceAll ("\u00a0", "");
Run Code Online (Sandbox Code Playgroud)

打印出来; 上周,Ovokerie Ogbeta进入了»Here

  • 遇到同样的问题,这应该是公认的答案. (3认同)