Re: [問題] String的問題
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
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 6 篇):