0
我希望我的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);
}
當我使用修剪它給輸出,大量的信息和 之間的空間SATISH
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
所以我可以重複多次刪除線? @Mike Samuel – satish