【发布时间】:2014-05-26 10:18:37
【问题描述】:
我想要我的 java 程序的输出没有空格, 我的代码是 -
Source source1=new Source(new URL(sourceUrlString1));
List<Element> temp1 = source1.getElementById("main").getAllElementsByClass("grid_3 alpha");
String line = temp1.toString();
String temps = line.trim();//using this
String temps = line.replaceAll("\\s+","")// or this
if(!temps.isEmpty())
{
sendResponse(resp, "Information for:"+searchWord+":" +temps);
}
当我使用 Trim 时,它会在输出信息和信息之间留出大量空间 饱和度
Information for::[
SATISH
JHOTWARA (JAIPUR)
Party:CPI
S/o|D/o|W/o: Om Prakash
Age: 42
当我使用String temps = line.replaceAll("\\s+","")时;
输出如下:
Information for::[<divclass="grid_3alpha"style='background:khaki;'><h2class="main-title">SatishKumar<fontcolor=greensize=1>(Winner)
ELECTEDFROMBIHARLEGISLATIVEASSEMBLY
<divclass="grid_2alpha">Party:JD(U)<divclass="grid_2alpha">S/o|D/o|W/o:JagdishPrasad<divclass
【问题讨论】: