Re: [問題] String的問題

看板java作者 (nothing here)時間16年前 (2008/04/02 14:13), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串3/6 (看更多)
public static List<String> stringToArrayFantasy(String testStr) { List destList=new ArrayList<String>(); int startIndex=0; for (; ; ) { if(testStr.indexOf(",", startIndex)!=-1) { String putStr=testStr.substring(0, testStr.indexOf(",",start Index)+1); destList.add(putStr); startIndex=testStr.indexOf(",", startIndex)+1; }else { break; } } return destList; } ※ 引述《breakofdawn (hi)》之銘言: : 我想要把一個用逗號分開的字串 : 譬如abc,def,ghi,jkl,mno, : 用stringtokenizer把各個被逗號分隔的字串取出 : 然後存入一個array : 之後再由左到右將 : abc,存入新的array的第一個值 : abc,def,是新array的第二個值 : abc,def,ghi是第三個值 : 一直存到最右邊 : 以上面的例子最後一個也就是第五個就是存全部abc,def,ghi,jkl,mno, : 我已經完成了前面的了想請問後面這個存入新array該如何做呢?謝謝 : int i=0, count=0; : StringTokenizer st = new StringTokenizer(rawString,","); : count=st.countTokens(); : String[] first = new String[count]; : String[] second = new String[count]; : while (st.hasMoreTokens()) { : first[i]=st.nextToken(); : i++; : } : 我這邊將first[0]變成了abc,first[1]變成了def...,etc : 之後想讓second[0]變成abc, : second[1]變成abc,def, ....,etc : 希望我表達的還算清楚.謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.108.28.85

04/02 15:17, , 1F
推這個
04/02 15:17, 1F
文章代碼(AID): #17yoGK86 (java)
文章代碼(AID): #17yoGK86 (java)