下面是一個好用的找出子字串的方法,text存你的字串,只要根據你的需求更改separator變數即可

範例如下:

//解析字串

String text=fdataInfo.getCell(i,"industry").toString();

int tcount =0;

char separator=',';

int index=0;

//計數有幾個

do

{

++tcount;

++index;

index=text.indexOf(separator,index);



}

while(index != -1);



//System.out.println("tcount:"+tcount);

String[] subStr = new String[tcount];



index=0;

int endindex=0;

//儲存子字串

for(int x=0; x {

endindex = text.indexOf(separator,index);



if (endindex==-1)

subStr[x]= text.substring(index);

else

subStr[x]= text.substring(index,endindex);



index=endindex+1;

}



//找出子字串

for (int x=0; x< subStr.length;x++)

{

System.out.println(subStr[x]);



}
arrow
arrow
    全站熱搜

    狼翔月影 發表在 痞客邦 留言(0) 人氣()